├── .gitmodules ├── CONTRIBUTING.md ├── LICENSE.md ├── Morphs └── Importers │ ├── .gitignore │ ├── Apps │ ├── CMakeLists.txt │ └── Transcode.CPP │ │ ├── CMakeLists.txt │ │ └── Source │ │ ├── Transcode.cpp │ │ ├── Transcode.h │ │ └── main.cpp │ ├── CMakeLists.txt │ ├── Dependencies │ ├── DirectXTex │ │ ├── CMakeDirectXTexBuild.txt │ │ ├── CMakeDirectXTexDownload.txt.in │ │ └── CMakeLists.txt │ ├── GLTFSDK │ │ ├── CMakeGLTFSDKDownload.txt.in │ │ └── CMakeLists.txt │ ├── RapidJSON │ │ ├── CMakeLists.txt │ │ └── CMakeRapidJSONDownload.txt.in │ └── SketchUpAPI-Windows │ │ └── FindSKPSDK.Windows.cmake │ ├── Transcoders │ ├── CMakeLists.txt │ ├── PluginSDK │ │ ├── CMakeLists.txt │ │ ├── Include │ │ │ └── PluginSDK │ │ │ │ ├── ExporterBase.h │ │ │ │ ├── FileParserBase.h │ │ │ │ ├── FractionalProgressCallback.h │ │ │ │ ├── IConverter.h │ │ │ │ ├── IExporter.h │ │ │ │ ├── IOutputStreamFactory.h │ │ │ │ ├── IParser.h │ │ │ │ ├── IResourceServer.h │ │ │ │ ├── ITranscoderBuffer.h │ │ │ │ ├── LineTokensPtr.h │ │ │ │ ├── LineTypeTranslator.h │ │ │ │ ├── PluginSDK_NugetVersion.h │ │ │ │ ├── ResourceServer.h │ │ │ │ ├── ResourceServerException.h │ │ │ │ ├── TokenParser.h │ │ │ │ ├── TranscodeOptions.h │ │ │ │ ├── TranscoderTextStream.h │ │ │ │ └── UpdateReporter.h │ │ └── Source │ │ │ ├── ExporterBase.cpp │ │ │ ├── FileParserBase.cpp │ │ │ ├── PluginSDKPch.cpp │ │ │ ├── PluginSDKPch.h │ │ │ ├── TokenParser.cpp │ │ │ ├── TranscodeOptions.cpp │ │ │ └── TranscoderTextStream.cpp │ └── Transcoders │ │ ├── CMakeLists.txt │ │ ├── Include │ │ ├── ExporterGLTF │ │ │ ├── Asset3DToGLTFConverter.h │ │ │ ├── ExporterGLB.h │ │ │ ├── ExporterGLTF.h │ │ │ ├── ExtensionsMSFT.h │ │ │ └── GLTFExportOptions.h │ │ ├── ExporterOBJ │ │ │ └── ExporterObj.h │ │ ├── ExporterSTL │ │ │ └── ExporterAsciiStl.h │ │ ├── ExporterTexture │ │ │ └── ExporterTexture.h │ │ ├── PluginSKP │ │ │ └── PluginSKP.h │ │ ├── TranscoderException.h │ │ ├── TranscoderGLTF │ │ │ ├── GLTFImportOptions.h │ │ │ ├── GLTFToAsset3DConverter.h │ │ │ ├── IStreamReaderRSAdapter.h │ │ │ ├── IStreamWriterOSFAdapter.h │ │ │ ├── ImporterGLB.h │ │ │ ├── ImporterGLTF.h │ │ │ ├── StringUtils.h │ │ │ ├── TranscoderGLB.h │ │ │ ├── TranscoderGLTF.h │ │ │ └── TransformMatrixUtils.h │ │ ├── TranscoderOBJ │ │ │ ├── AuthorType.h │ │ │ ├── GeometryLineType.h │ │ │ ├── GeometryParser.h │ │ │ ├── MaterialParser.h │ │ │ ├── MtlLineType.h │ │ │ ├── MtlTextureMapOptions.h │ │ │ └── TranscoderOBJ.h │ │ ├── TranscoderPLY │ │ │ ├── PLYParser.h │ │ │ └── TranscoderPLY.h │ │ ├── TranscoderSTL │ │ │ ├── StlAsciiParser.h │ │ │ ├── StlBinaryParser.h │ │ │ └── TranscoderSTL.h │ │ └── Transcoders.h │ │ └── Source │ │ ├── ExporterGLTF │ │ ├── Asset3DToGLTFConverter.cpp │ │ ├── ExporterGLB.cpp │ │ ├── ExporterGLTF.cpp │ │ └── ExtensionsMSFT.cpp │ │ ├── ExporterOBJ │ │ └── ExporterObj.cpp │ │ ├── ExporterSTL │ │ └── ExporterAsciiStl.cpp │ │ ├── ExporterTexture │ │ └── ExporterTexture.cpp │ │ ├── MemoryStream.h │ │ ├── TranscoderException.cpp │ │ ├── TranscoderGLTF │ │ ├── GLTFToAsset3DConverter.cpp │ │ ├── ImporterGLB.cpp │ │ ├── ImporterGLTF.cpp │ │ ├── TranscoderGLB.cpp │ │ └── TranscoderGLTF.cpp │ │ ├── TranscoderOBJ │ │ ├── GeometryParser.cpp │ │ ├── MaterialParser.cpp │ │ └── TranscoderOBJ.cpp │ │ ├── TranscoderPLY │ │ ├── PLYParser.cpp │ │ └── TranscoderPLY.cpp │ │ ├── TranscoderSKP │ │ ├── ImporterSKP.cpp │ │ ├── ImporterSKP.h │ │ ├── PluginSKP.cpp │ │ ├── SkpUtils.cpp │ │ └── SkpUtils.h │ │ ├── TranscoderSTL │ │ ├── StlAsciiParser.cpp │ │ ├── StlBinaryParser.cpp │ │ └── TranscoderSTL.cpp │ │ ├── Transcoders.cpp │ │ ├── TranscodersPch.cpp │ │ ├── TranscodersPch.h │ │ ├── TranscodersTelemetryHelper.cpp │ │ ├── TranscodersTelemetryHelper.h │ │ └── TranscodersV2Json.cpp │ └── Utils │ ├── Asset3D │ ├── CMakeLists.txt │ ├── Include │ │ └── Asset3D │ │ │ ├── Animation.h │ │ │ ├── Asset3D.h │ │ │ ├── Asset3DTraverser.h │ │ │ ├── BoundingBox.h │ │ │ ├── Camera.h │ │ │ ├── ExtensionsPayloadData.h │ │ │ ├── Geometry.h │ │ │ ├── IAsset3DProcessor.h │ │ │ ├── ITraversable.h │ │ │ ├── MaterialConversionUtils.h │ │ │ ├── MaterialDescriptor.h │ │ │ ├── MaterialLayer.h │ │ │ ├── Mesh.h │ │ │ ├── Projection.h │ │ │ ├── SceneNode.h │ │ │ ├── TextureDescriptor.h │ │ │ └── TexturePackingUtils.h │ └── Source │ │ ├── Asset3D.cpp │ │ ├── Asset3DPch.cpp │ │ ├── Asset3DPch.h │ │ ├── Asset3DTraverser.cpp │ │ ├── BoundingBox.cpp │ │ ├── Geometry.cpp │ │ ├── ITraversableBase.cpp │ │ ├── MaterialConversionUtils.cpp │ │ ├── MaterialDescriptor.cpp │ │ ├── Mesh.cpp │ │ ├── SceneNode.cpp │ │ ├── TextureDescriptor.cpp │ │ └── TexturePackingUtils.cpp │ ├── CMakeLists.txt │ ├── CanvasTex │ ├── CMakeLists.txt │ ├── Include │ │ └── CanvasTex │ │ │ ├── CanvasTex.h │ │ │ ├── Format.h │ │ │ ├── Image.h │ │ │ ├── ScratchImage.h │ │ │ └── TextureMetadata.h │ └── Source │ │ ├── CanvasTexUtils.h │ │ └── Win │ │ ├── CanvasTex.cpp │ │ ├── CanvasTexPch.cpp │ │ ├── CanvasTexPch.h │ │ ├── DxDevice.cpp │ │ ├── DxDevice.h │ │ ├── FormatConversion.cpp │ │ ├── FormatConversion.h │ │ ├── Image.cpp │ │ ├── Image.h │ │ ├── MedianCutQuantizer.cpp │ │ ├── MedianCutQuantizer.h │ │ ├── ScratchImage.cpp │ │ ├── ScratchImage.h │ │ ├── TextureMetadata.cpp │ │ ├── TextureMetadata.h │ │ ├── WindowsCommon.cpp │ │ └── WindowsCommon.h │ ├── CoreUtils │ ├── CMakeLists.txt │ ├── Include │ │ ├── CoreUtils │ │ │ ├── Align.h │ │ │ ├── AnimationNameChecker.h │ │ │ ├── Assert.h │ │ │ ├── BabylonConstExpr.h │ │ │ ├── BabylonSDK.h │ │ │ ├── BabylonSal.h │ │ │ ├── BabylonTelemetryException.h │ │ │ ├── BasicMemoryStream.h │ │ │ ├── BasicVectorStream.h │ │ │ ├── CRC64.h │ │ │ ├── Cancellation.h │ │ │ ├── Cast.h │ │ │ ├── ConfigurationManagerJson.h │ │ │ ├── ConfigurationValue.h │ │ │ ├── DirectProperty.h │ │ │ ├── Enum.h │ │ │ ├── EnumFlagSet.h │ │ │ ├── FileIO.h │ │ │ ├── GLTFChannelAnimations.h │ │ │ ├── GLTFSkins.h │ │ │ ├── Gltf.h │ │ │ ├── Hash.h │ │ │ ├── IConfigurationManager.h │ │ │ ├── IO.h │ │ │ ├── ITelemetryManager.h │ │ │ ├── IndirectProperty.h │ │ │ ├── LexicalCast.h │ │ │ ├── Math │ │ │ │ ├── BabylonMath.h │ │ │ │ ├── SimpleMath.h │ │ │ │ └── SimpleMath.inl │ │ │ ├── Memory.h │ │ │ ├── Optional.h │ │ │ ├── Pimpl.h │ │ │ ├── PimplImpl.h │ │ │ ├── Platform.h │ │ │ ├── Pointers.h │ │ │ ├── Property.h │ │ │ ├── RapidJson.h │ │ │ ├── ScopeWarden.h │ │ │ ├── SharedMutex.h │ │ │ ├── SmartThrow.h │ │ │ ├── StreamUtils.h │ │ │ ├── StringUtils.h │ │ │ ├── ThreadHelpers.h │ │ │ ├── ThreadPool.h │ │ │ ├── Trace.h │ │ │ ├── Tracked.h │ │ │ ├── Tweening │ │ │ │ ├── CurveFactory.h │ │ │ │ ├── Curves.h │ │ │ │ ├── ICurve.h │ │ │ │ ├── ITweenable.h │ │ │ │ ├── Tween.h │ │ │ │ ├── TweenManager.h │ │ │ │ ├── TweenOptions.h │ │ │ │ ├── TweenProperty.h │ │ │ │ └── TweenPropertySpecializations.h │ │ │ └── Version.h │ │ └── DirectXMath │ │ │ ├── DirectXCollision.h │ │ │ ├── DirectXCollision.inl │ │ │ ├── DirectXColors.h │ │ │ ├── DirectXMath.h │ │ │ ├── DirectXMathConvert.inl │ │ │ ├── DirectXMathMatrix.inl │ │ │ ├── DirectXMathMisc.inl │ │ │ ├── DirectXMathVector.inl │ │ │ ├── DirectXPackedVector.h │ │ │ └── DirectXPackedVector.inl │ └── Source │ │ ├── Assert.cpp │ │ ├── BabylonTelemetryException.cpp │ │ ├── CRC64.cpp │ │ ├── Cancellation.cpp │ │ ├── ConfigurationManagerBase.cpp │ │ ├── ConfigurationManagerJson.cpp │ │ ├── ConfigurationValue.cpp │ │ ├── CoreUtilsPch.h │ │ ├── GLTFChannelAnimations.cpp │ │ ├── GLTFSkins.cpp │ │ ├── Gltf.cpp │ │ ├── IO.cpp │ │ ├── LexicalCast.cpp │ │ ├── Memory.cpp │ │ ├── PlatformLogger.h │ │ ├── SimpleMath.cpp │ │ ├── SmartThrow.cpp │ │ ├── StringUtils.cpp │ │ ├── TelemetryManager.cpp │ │ ├── ThreadHelpers.cpp │ │ ├── ThreadPool.cpp │ │ ├── Trace.cpp │ │ ├── Tracked.cpp │ │ ├── Tweening │ │ ├── CurveFactory.cpp │ │ ├── Curves.cpp │ │ ├── TweenManager.cpp │ │ └── TweenPropertySpecializations.cpp │ │ ├── Version.cpp │ │ └── Win │ │ ├── CoreUtilsPch.cpp │ │ ├── FileIO.cpp │ │ ├── PlatformLogger.cpp │ │ └── SharedMutexWin.cpp │ ├── Framework │ ├── CMakeLists.txt │ ├── Include │ │ └── Framework │ │ │ ├── AnimationSegment.h │ │ │ ├── Async.h │ │ │ ├── Cancellation.h │ │ │ ├── Endian.h │ │ │ ├── Enums.h │ │ │ ├── ExtensionHeader.h │ │ │ ├── FormatWriterUtils.h │ │ │ ├── Frame.h │ │ │ ├── GeometryUtils.h │ │ │ ├── GeometryWriter.h │ │ │ ├── IBuffer.h │ │ │ ├── ITelemetryTraceLogger.h │ │ │ ├── ManifestParser.h │ │ │ ├── MaterialSegment.h │ │ │ ├── MaterialWriter.h │ │ │ ├── Memory.h │ │ │ ├── MemoryBuffer.h │ │ │ ├── MeshMaker.h │ │ │ ├── MeshSegment.h │ │ │ ├── MetadataDefinition.h │ │ │ ├── MetadataWriter.h │ │ │ ├── PerformanceLoggingProviders.h │ │ │ ├── PerformanceTraceLogging.h │ │ │ ├── Plugin.h │ │ │ ├── Pointers.h │ │ │ ├── SceneSegment.h │ │ │ ├── SceneWriter.h │ │ │ ├── TelemetryTraceDualLogger.h │ │ │ ├── TelemetryTraceLoggerAliases.h │ │ │ ├── TelemetryTraceLoggerFactory.h │ │ │ ├── TelemetryTraceLoggerJson.h │ │ │ ├── TextureSegment.h │ │ │ ├── TextureWriter.h │ │ │ ├── TraceLoggingCorrelationVector.hpp │ │ │ ├── Types.h │ │ │ └── Vertex.h │ └── Source │ │ ├── Async.cpp │ │ ├── Cancellation.cpp │ │ ├── FormatWriterUtils.cpp │ │ ├── FrameworkPch.cpp │ │ ├── FrameworkPch.h │ │ ├── GeometryUtils.cpp │ │ ├── GeometryWriter.cpp │ │ ├── ITelemetryTraceLogger.cpp │ │ ├── ManifestParser.cpp │ │ ├── MaterialWriter.cpp │ │ ├── MeshMaker.cpp │ │ ├── MetadataWriter.cpp │ │ ├── PerformanceLoggingProviders.cpp │ │ ├── PerformanceTraceLogging.cpp │ │ ├── PrivateAsync.h │ │ ├── SceneWriter.cpp │ │ ├── TelemetryTraceDualLogger.cpp │ │ ├── TelemetryTraceLoggerJson.cpp │ │ ├── TextureWriter.cpp │ │ └── Win │ │ ├── PerformanceLoggingProvidersWin.cpp │ │ ├── PerformanceLoggingProvidersWin.h │ │ ├── TelemetryTraceLoggerFactoryWin.cpp │ │ ├── TelemetryTraceLoggerWin.cpp │ │ └── TelemetryTraceLoggerWin.h │ └── ImagingComponent │ ├── CMakeLists.txt │ ├── Include │ └── ImagingComponent │ │ ├── Detection.h │ │ ├── Encoding.h │ │ ├── Gif.h │ │ ├── ImagingComponent.h │ │ ├── Processing.h │ │ └── SpriteSheet.h │ └── Source │ ├── Common.cpp │ ├── Common.h │ ├── Detection.cpp │ ├── Encoding.cpp │ ├── Processing.cpp │ ├── SpriteSheet.cpp │ └── Win │ ├── Gif.cpp │ ├── WindowsCommon.cpp │ └── WindowsCommon.h └── README.md /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "Morphs/Importers/Submodules/glTF-SDK"] 2 | path = Morphs/Importers/Submodules/glTF-SDK 3 | url = https://github.com/microsoft/glTF-SDK.git 4 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | For the time being, this project is currently not accepting any pull requests from external sources. 4 | Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, 5 | and actually do, grant us the rights to use your contribution. For details, visit 6 | https://cla.microsoft.com. 7 | 8 | When you submit a pull request, a CLA-bot will automatically determine whether you need 9 | to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the 10 | instructions provided by the bot. You will only need to do this once across all repositories using our CLA. 11 | 12 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 13 | For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) 14 | or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | ## MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Morphs/Importers/.gitignore: -------------------------------------------------------------------------------- 1 | /Build 2 | .DS_Store 3 | .vscode 4 | -------------------------------------------------------------------------------- /Morphs/Importers/Apps/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Transcode.CPP) 2 | -------------------------------------------------------------------------------- /Morphs/Importers/Apps/Transcode.CPP/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Transcode.CPP 2 | set(SOURCES 3 | "Source/main.cpp" 4 | "Source/Transcode.cpp" 5 | "Source/Transcode.h") 6 | 7 | add_executable(Transcode.CPP ${SOURCES}) 8 | 9 | set_target_properties(Transcode.CPP PROPERTIES 10 | FOLDER "Apps" 11 | ) 12 | 13 | target_include_directories(Transcode.CPP 14 | PRIVATE "${CMAKE_CURRENT_LIST_DIR}/Source/" 15 | ) 16 | 17 | target_compile_definitions(Transcode.CPP 18 | PRIVATE NOMINMAX) 19 | 20 | target_link_libraries(Transcode.CPP 21 | CoreUtils 22 | Framework 23 | CanvasTex 24 | ImagingComponent 25 | Asset3D 26 | Transcoders 27 | ) 28 | 29 | if(WIN32) 30 | target_link_libraries(Transcode.CPP 31 | ole32 32 | advapi32 33 | secur32 34 | ) 35 | 36 | if(SKPSDK_FOUND) 37 | target_link_libraries(Transcode.CPP 38 | SKPSDK 39 | ) 40 | 41 | if(SKPSDK_MULTI_FILES) 42 | add_custom_command(TARGET Transcode.CPP POST_BUILD 43 | COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ 44 | COMMAND ${CMAKE_COMMAND} -E copy_if_different $/SketchUpCommonPreferences.dll $ 45 | ) 46 | endif() 47 | endif() 48 | endif() 49 | -------------------------------------------------------------------------------- /Morphs/Importers/Apps/Transcode.CPP/Source/Transcode.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | 3 | #include 4 | 5 | namespace Babylon 6 | { 7 | void Transcode( 8 | const std::string& inputFile, 9 | const std::string& outputFile, 10 | const std::unordered_map& importOptions, 11 | const std::unordered_map& exportOptions, 12 | const std::string& outputDirectory = ""); 13 | std::string GetImportHelp(const std::string& format); 14 | std::string GetExportHelp(const std::string& format); 15 | } 16 | -------------------------------------------------------------------------------- /Morphs/Importers/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | project(BabylonImporters) 3 | 4 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) 5 | 6 | set(CMAKE_CXX_STANDARD 14) 7 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 8 | 9 | # External Dependencies 10 | add_subdirectory(Dependencies/RapidJSON) 11 | add_subdirectory(Dependencies/GLTFSDK) 12 | add_subdirectory(Dependencies/DirectXTex) 13 | 14 | # Load SketchUP (if available) 15 | if(WIN32) 16 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/Dependencies/SketchUpAPI-Windows") 17 | find_package(SKPSDK.Windows) 18 | 19 | if(SKPSDK_FOUND) 20 | add_definitions(-DHAS_SKP_LIB) 21 | endif() 22 | endif() 23 | 24 | add_subdirectory(Utils) 25 | add_subdirectory(Transcoders) 26 | add_subdirectory(Apps) 27 | -------------------------------------------------------------------------------- /Morphs/Importers/Dependencies/DirectXTex/CMakeDirectXTexBuild.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | project (DirectXTex) 3 | 4 | file(GLOB DIRECTXTEX_SOURCE_FILES 5 | ${CMAKE_CURRENT_LIST_DIR}/DirectXTex/BC.cpp 6 | ${CMAKE_CURRENT_LIST_DIR}/DirectXTex/BC4BC5.cpp 7 | ${CMAKE_CURRENT_LIST_DIR}/DirectXTex/BC6HBC7.cpp 8 | ${CMAKE_CURRENT_LIST_DIR}/DirectXTex/BCDirectCompute.cpp 9 | ${CMAKE_CURRENT_LIST_DIR}/DirectXTex/DirectXTexCompress.cpp 10 | ${CMAKE_CURRENT_LIST_DIR}/DirectXTex/DirectXTexCompressGPU.cpp 11 | ${CMAKE_CURRENT_LIST_DIR}/DirectXTex/DirectXTexConvert.cpp 12 | ${CMAKE_CURRENT_LIST_DIR}/DirectXTex/DirectXTexD3D11.cpp 13 | ${CMAKE_CURRENT_LIST_DIR}/DirectXTex/DirectXTexDDS.cpp 14 | ${CMAKE_CURRENT_LIST_DIR}/DirectXTex/DirectXTexFlipRotate.cpp 15 | ${CMAKE_CURRENT_LIST_DIR}/DirectXTex/DirectXTexHDR.cpp 16 | ${CMAKE_CURRENT_LIST_DIR}/DirectXTex/DirectXTexImage.cpp 17 | ${CMAKE_CURRENT_LIST_DIR}/DirectXTex/DirectXTexMipMaps.cpp 18 | ${CMAKE_CURRENT_LIST_DIR}/DirectXTex/DirectXTexMisc.cpp 19 | ${CMAKE_CURRENT_LIST_DIR}/DirectXTex/DirectXTexNormalMaps.cpp 20 | ${CMAKE_CURRENT_LIST_DIR}/DirectXTex/DirectXTexPMAlpha.cpp 21 | ${CMAKE_CURRENT_LIST_DIR}/DirectXTex/DirectXTexResize.cpp 22 | ${CMAKE_CURRENT_LIST_DIR}/DirectXTex/DirectXTexTGA.cpp 23 | ${CMAKE_CURRENT_LIST_DIR}/DirectXTex/DirectXTexUtil.cpp 24 | ${CMAKE_CURRENT_LIST_DIR}/DirectXTex/DirectXTexWIC.cpp 25 | ) 26 | 27 | add_library(DirectXTex STATIC ${DIRECTXTEX_SOURCE_FILES}) 28 | 29 | target_include_directories(DirectXTex 30 | PUBLIC "${CMAKE_CURRENT_LIST_DIR}/DirectXTex" 31 | ) 32 | -------------------------------------------------------------------------------- /Morphs/Importers/Dependencies/DirectXTex/CMakeDirectXTexDownload.txt.in: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.2) 2 | 3 | project(DirectXTex-download NONE) 4 | 5 | include(ExternalProject) 6 | ExternalProject_Add(DirectXTex 7 | # Code from https://github.com/Microsoft/DirectXTex.git 8 | # Branch "master" 9 | # Commit 3950756b534e42de1ada8222398fbc1ac7432fca 10 | GIT_REPOSITORY https://github.com/microsoft/DirectXTex.git 11 | GIT_TAG 3950756b534e42de1ada8222398fbc1ac7432fca 12 | SOURCE_DIR "${CMAKE_BINARY_DIR}/DirectXTex-src" 13 | BINARY_DIR "${CMAKE_BINARY_DIR}/DirectXTex-build" 14 | CONFIGURE_COMMAND "" 15 | BUILD_COMMAND "" 16 | INSTALL_COMMAND "" 17 | TEST_COMMAND "" 18 | ) 19 | -------------------------------------------------------------------------------- /Morphs/Importers/Dependencies/DirectXTex/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Download and unpack DirectXTex at configure time 2 | configure_file(CMakeDirectXTexDownload.txt.in ${CMAKE_BINARY_DIR}/DirectXTex-download/CMakeLists.txt) 3 | 4 | execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . 5 | RESULT_VARIABLE result 6 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/DirectXTex-download ) 7 | if(result) 8 | message(FATAL_ERROR "CMake step for DirectXTex failed: ${result}") 9 | endif() 10 | execute_process(COMMAND ${CMAKE_COMMAND} --build . 11 | RESULT_VARIABLE result 12 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/DirectXTex-download ) 13 | if(result) 14 | message(FATAL_ERROR "Build step for DirectXTex failed: ${result}") 15 | endif() 16 | 17 | # DirectXTex doesn't use CMake for its build. 18 | # We have two options here. Use msbuild to build the solution files that are in the git repo 19 | # or use CMake to add the source files to the build 20 | # Using msbuild means that we would have to build all the configurations here in the "Configure" step. 21 | # It also makes it less configurable (switch between /MD and /MT compile options, for example) 22 | 23 | # We are going to try just building the source files 24 | 25 | # Copy a CMakeLists.txt into the source folder that will be used by the build. 26 | configure_file(CMakeDirectXTexBuild.txt ${CMAKE_BINARY_DIR}/DirectXTex-src/CMakeLists.txt COPYONLY) 27 | 28 | # Add the CMakeLists.txt copied above into our build. 29 | add_subdirectory(${CMAKE_BINARY_DIR}/DirectXTex-src 30 | ${CMAKE_BINARY_DIR}/DirectXTex-build) 31 | 32 | # Force DirectXTex targets in sub-folder in solution 33 | set_target_properties(DirectXTex PROPERTIES 34 | FOLDER "Dependencies" 35 | ) 36 | -------------------------------------------------------------------------------- /Morphs/Importers/Dependencies/GLTFSDK/CMakeGLTFSDKDownload.txt.in: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.2) 2 | 3 | project(GLTFSDK-download NONE) 4 | 5 | include(ExternalProject) 6 | ExternalProject_Add(GLTFSDK-external 7 | # Code from https://github.com/Microsoft/glTF-SDK 8 | # Release "r1.9.3.0" 9 | GIT_REPOSITORY https://github.com/microsoft/glTF-SDK.git 10 | GIT_TAG 204d699802d62b1bd7ae2dede984fa0721fde45a 11 | SOURCE_DIR "${CMAKE_BINARY_DIR}/GLTFSDK-src" 12 | BINARY_DIR "${CMAKE_BINARY_DIR}/GLTFSDK-build" 13 | CONFIGURE_COMMAND "" 14 | BUILD_COMMAND "" 15 | INSTALL_COMMAND "" 16 | TEST_COMMAND "" 17 | ) 18 | -------------------------------------------------------------------------------- /Morphs/Importers/Dependencies/GLTFSDK/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Download and unpack GLTFSDK at configure time 2 | configure_file(CMakeGLTFSDKDownload.txt.in ${CMAKE_BINARY_DIR}/GLTFSDK-download/CMakeLists.txt) 3 | execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . 4 | RESULT_VARIABLE result 5 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/GLTFSDK-download ) 6 | if(result) 7 | message(FATAL_ERROR "CMake step for GLTFSDK failed: ${result}") 8 | endif() 9 | execute_process(COMMAND ${CMAKE_COMMAND} --build . 10 | RESULT_VARIABLE result 11 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/GLTFSDK-download ) 12 | if(result) 13 | message(FATAL_ERROR "Build step for GLTFSDK failed: ${result}") 14 | endif() 15 | 16 | # Instead of adding the root of the GLTFSDK to the cmake configuration (which brings in the unit tests and RapidJSON and googletest) 17 | # We just include the GLTFSDK library and dependencies. 18 | # TODO: Once the GLTFSDK has conditional tests around the inclusion of RapidJSON and googletest (to avoid duplicate definitions), 19 | # this can be reveted to the previous version. 20 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_BINARY_DIR}/GLTFSDK-src/Build/CMake/Modules") 21 | add_subdirectory(${CMAKE_BINARY_DIR}/GLTFSDK-src/GLTFSDK ${CMAKE_BINARY_DIR}/GLTFSDK-build) 22 | 23 | # Force GLTFSDK targets in sub-folder in solution 24 | set_target_properties(GLTFSDK PROPERTIES 25 | FOLDER "Dependencies" 26 | ) 27 | -------------------------------------------------------------------------------- /Morphs/Importers/Dependencies/RapidJSON/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Check if this target has already been included elsewhere (like through another external project like GLTFSDK) 2 | if (TARGET RapidJSON) 3 | get_target_property(IncludeDirs RapidJSON INTERFACE_INCLUDE_DIRECTORIES) 4 | message(AUTHOR_WARNING "RapidJSON target already defined. Will be included from here ${IncludeDirs}") 5 | return() 6 | endif() 7 | 8 | # Download and unpack RapidJSON at configure time 9 | configure_file(CMakeRapidJSONDownload.txt.in ${CMAKE_BINARY_DIR}/RapidJSON-download/CMakeLists.txt) 10 | execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . 11 | RESULT_VARIABLE result 12 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/RapidJSON-download ) 13 | if(result) 14 | message(FATAL_ERROR "CMake step for RapidJSON failed: ${result}") 15 | endif() 16 | execute_process(COMMAND ${CMAKE_COMMAND} --build . 17 | RESULT_VARIABLE result 18 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/RapidJSON-download ) 19 | if(result) 20 | message(FATAL_ERROR "Build step for RapidJSON failed: ${result}") 21 | endif() 22 | 23 | # Disable building the docs, tests, and examples 24 | set(RAPIDJSON_BUILD_TESTS OFF CACHE BOOL "" FORCE) 25 | set(RAPIDJSON_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) 26 | set(RAPIDJSON_BUILD_DOC OFF CACHE BOOL "" FORCE) 27 | 28 | # Add RapidJSON directly to our build. 29 | add_subdirectory(${CMAKE_BINARY_DIR}/RapidJSON-src 30 | ${CMAKE_BINARY_DIR}/RapidJSON-build 31 | EXCLUDE_FROM_ALL) 32 | 33 | # Set the RapidJSONConfig.cmake path and make find_package to work in config mode explicitly. 34 | set(RapidJSON_DIR "${CMAKE_BINARY_DIR}/RapidJSON-build" CACHE LOCATION "Specific configuration file location") 35 | find_package(RapidJSON REQUIRED CONFIG) 36 | 37 | add_library(RapidJSON INTERFACE IMPORTED GLOBAL) 38 | set_target_properties(RapidJSON PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${RapidJSON_INCLUDE_DIRS}) 39 | -------------------------------------------------------------------------------- /Morphs/Importers/Dependencies/RapidJSON/CMakeRapidJSONDownload.txt.in: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.2) 2 | 3 | project(RapidJSON-download NONE) 4 | 5 | include(ExternalProject) 6 | ExternalProject_Add(RapidJSON 7 | # Code from https://github.com/Tencent/rapidjson.git 8 | # Branch "master" 9 | # Commit 17ae6ffa857173c25708e61610121bc908c0a6cd 10 | GIT_REPOSITORY https://github.com/fergsatwork/rapidjson.git 11 | GIT_TAG 17ae6ffa857173c25708e61610121bc908c0a6cd 12 | SOURCE_DIR "${CMAKE_BINARY_DIR}/RapidJSON-src" 13 | BINARY_DIR "${CMAKE_BINARY_DIR}/RapidJSON-build" 14 | CONFIGURE_COMMAND "" 15 | BUILD_COMMAND "" 16 | INSTALL_COMMAND "" 17 | TEST_COMMAND "" 18 | ) 19 | -------------------------------------------------------------------------------- /Morphs/Importers/Dependencies/SketchUpAPI-Windows/FindSKPSDK.Windows.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9) 2 | 3 | # Try to find the SketchUp SDK and load it. It can be referenced in the code by using the 'SKPSDK' target name. 4 | if(NOT SKPSDK_CHECK_RUN) 5 | set(SKPSDK_CHECK_RUN TRUE) 6 | 7 | if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/FindSKPSDK.Win32.cmake") 8 | set(SKPSDK_FOUND TRUE) 9 | find_package(SKPSDK.Win32 COMPONENTS ${CMAKE_GENERATOR_PLATFORM}) 10 | message(STATUS "Found SKPSDK.Win32") 11 | elseif(EXISTS "${CMAKE_CURRENT_LIST_DIR}/binaries/sketchup/x64/SketchUpAPI.dll" AND "${CMAKE_GENERATOR_PLATFORM}" STREQUAL "x64") 12 | set(SKPSDK_FOUND TRUE) 13 | set(SKPSDK_MULTI_FILES TRUE) 14 | add_library(SKPSDK SHARED IMPORTED GLOBAL) 15 | set_target_properties(SKPSDK PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_LIST_DIR}/headers") 16 | set_target_properties(SKPSDK PROPERTIES IMPORTED_IMPLIB "${CMAKE_CURRENT_LIST_DIR}/binaries/sketchup/x64/SketchUpAPI.lib") 17 | set_target_properties(SKPSDK PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_LIST_DIR}/binaries/sketchup/x64/SketchUpAPI.dll") 18 | set_target_properties(SKPSDK PROPERTIES IMPORTED_LINK_DEPENDENT_LIBRARIES "${CMAKE_CURRENT_LIST_DIR}/binaries/sketchup/x64/SketchUpCommonPreferences.dll") 19 | message(STATUS "Loaded SKPSDK") 20 | else() 21 | set(SKPSDK_FOUND FALSE) 22 | message(STATUS "SKPSDK not found.") 23 | endif() 24 | endif() 25 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(PluginSDK) 2 | add_subdirectory(Transcoders) 3 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/PluginSDK/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # PluginSDK 2 | file(GLOB SOURCES CONFIGURE_DEPENDS 3 | "Include/PluginSDK/*.h" 4 | "Source/*.h" 5 | "Source/*.cpp") 6 | 7 | add_library(PluginSDK ${SOURCES}) 8 | 9 | target_include_directories(PluginSDK PUBLIC "Include") 10 | 11 | target_compile_definitions(PluginSDK 12 | PRIVATE NOMINMAX) 13 | 14 | set_property(TARGET PluginSDK PROPERTY FOLDER Transcoders) 15 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES}) 16 | 17 | target_link_libraries(PluginSDK 18 | CoreUtils 19 | Framework 20 | CanvasTex 21 | ImagingComponent 22 | Asset3D 23 | RapidJSON 24 | ) 25 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/PluginSDK/Include/PluginSDK/FileParserBase.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace Babylon 16 | { 17 | namespace Transcoder 18 | { 19 | class TranscoderTextStream; 20 | 21 | /* 22 | * The class is used to parse a text file containing 3D asset data. 23 | * Child classes need to implement ProcessNonEmptyLine() and FinalizeFile() 24 | * to control the creation of different Descriptors to be encoded. 25 | */ 26 | class FileParserBase : public IParser 27 | { 28 | public: 29 | explicit FileParserBase(IResourceServer& resourceServer, UpdateReporter* updateReporter); 30 | virtual ~FileParserBase(); 31 | 32 | virtual void ParseStream(std::shared_ptr stream, size_t maxLineSize = 4096); 33 | LineTokensPtr GetTokens(char* line, size_t lineLength, const char* m_delimiters = "\n \r\t") const; 34 | virtual size_t ReadLine(TranscoderTextStream* stream, char* outputBuffer, size_t maxLineSize); 35 | 36 | protected: 37 | void ParseLine(char* line, size_t lineLength); 38 | 39 | virtual void ProcessNonEmptyLine(LineTokensPtr& tokens) = 0; 40 | virtual void FinalizeParseStream(void) = 0; 41 | 42 | UpdateReporter* m_progressReporter; 43 | size_t m_charactersRead; 44 | size_t m_streamLength; 45 | /// Starting chars of a line comment. Example // or # 46 | std::string m_commentChars; 47 | }; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/PluginSDK/Include/PluginSDK/FractionalProgressCallback.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | #include 8 | #include 9 | 10 | namespace Babylon 11 | { 12 | namespace Transcoder 13 | { 14 | /// \brief 15 | /// FractionalProgressCallback is the function signature for progress callbacks, where the float 16 | /// parameter represents the fractional progress from 0.0 to 1.0. 17 | /// 18 | /// SUGGESTED EXTENSION 19 | /// ------------------- 20 | /// 21 | /// This should be extended to support the notion of sub-tasks / stages with decoupled progress. Stages 22 | /// should be: 23 | /// a) Not fixed at run time. Each importer/exporter may have different stages, so declaring a list 24 | /// of stages by string seems appropriate 25 | /// b) Declared up-front, meaning that it's possible to display a meaningful sense of partial completeness 26 | /// 27 | /// For example: 28 | /// 29 | /// \verbatim 30 | /// Parsing OBJ: 97% [********* ] 31 | /// Consolidating vertices: 0% [ ] 32 | /// Fetching textures: 25% [** ] 33 | /// \endverbatim 34 | using FractionalProgressCallback = std::function; 35 | } 36 | } -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/PluginSDK/Include/PluginSDK/IConverter.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include 9 | 10 | namespace Babylon 11 | { 12 | namespace Framework 13 | { 14 | struct Frame; 15 | } 16 | 17 | namespace Transcoder 18 | { 19 | class IConverter 20 | { 21 | public: 22 | virtual void ConversionCompleted(BabylonAsyncStatus status) = 0; 23 | virtual void FrameCreated(Babylon::Framework::Frame* frame, uint32_t size) = 0; 24 | }; 25 | } 26 | } -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/PluginSDK/Include/PluginSDK/IExporter.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | #include 9 | #include 10 | #include 11 | 12 | namespace Lift 13 | { 14 | namespace Babylon 15 | { 16 | namespace Transcoder 17 | { 18 | // TODO: Add a generic (templated) enum to string conversion, so we can use that to generate 19 | // file extension automatically. 20 | enum class SupportedModelTypes 21 | { 22 | FBX = 0, 23 | ThreeMF = 1 24 | }; 25 | 26 | class IExporter 27 | { 28 | public: 29 | virtual std::shared_ptr> Export(const void* buffer, uint32_t buffersizeinbytes) = 0; 30 | }; 31 | } 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/PluginSDK/Include/PluginSDK/IOutputStreamFactory.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace Babylon 13 | { 14 | namespace Transcoder 15 | { 16 | /// Common std::ostream creation interface used by all 'ExportStatic' methods 17 | class IOutputStreamFactory 18 | { 19 | public: 20 | virtual ~IOutputStreamFactory() = default; 21 | 22 | /// Implementing code must construct a std::ostream for the given streamName (e.g. return std::make_shared(streamName); ) 23 | virtual std::shared_ptr CreateStream(const std::string& streamName) = 0; 24 | }; 25 | } 26 | }; -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/PluginSDK/Include/PluginSDK/IParser.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace Babylon 15 | { 16 | namespace Transcoder 17 | { 18 | class TextureFactory; 19 | 20 | /* 21 | * The class is used to parse a text file containing 3D asset data. 22 | * Child classes need to implement ProcessNonEmptyLine() and FinalizeFile() 23 | * to control the creation of different Descriptors to be encoded to BXF. 24 | */ 25 | class IParser 26 | { 27 | public: 28 | explicit IParser(IResourceServer& resourceServer) : 29 | m_resourceServer(resourceServer) 30 | { 31 | } 32 | 33 | protected: 34 | IResourceServer& m_resourceServer; 35 | }; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/PluginSDK/Include/PluginSDK/IResourceServer.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include 9 | 10 | namespace Babylon 11 | { 12 | namespace Transcoder 13 | { 14 | class IResourceServer 15 | { 16 | public: 17 | virtual ~IResourceServer() = default; 18 | 19 | /// Implementors must provide this blocking method to return the resource (or nullptr if the resource couldn't be located) 20 | virtual std::shared_ptr RequestResource(const std::string& fileName) const = 0; 21 | 22 | std::shared_ptr RequestTextFileResource(const std::string& fileName) const 23 | { 24 | if (auto stream = RequestResource(fileName)) 25 | { 26 | //Decorate the incoming stream without copying it 27 | return std::make_shared(stream); 28 | } 29 | return nullptr; 30 | } 31 | }; 32 | } 33 | } -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/PluginSDK/Include/PluginSDK/ITranscoderBuffer.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include 9 | 10 | namespace Babylon 11 | { 12 | namespace Transcoder 13 | { 14 | class ITranscoderBuffer 15 | { 16 | public: 17 | virtual size_t GetBufferSize() const = 0; 18 | virtual const void* GetBufferPtr() = 0; 19 | }; 20 | } // Transcoder 21 | } // Babylon 22 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/PluginSDK/Include/PluginSDK/LineTokensPtr.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace Babylon 13 | { 14 | namespace Transcoder 15 | { 16 | typedef std::unique_ptr> LineTokensPtr; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/PluginSDK/Include/PluginSDK/LineTypeTranslator.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | #include 8 | 9 | namespace Babylon { 10 | namespace Transcoder { 11 | template 12 | class LineTypeTranslator 13 | { 14 | public: 15 | ~LineTypeTranslator() {}; 16 | 17 | explicit LineTypeTranslator(std::map& typeMap); 18 | inline T LookUp(const std::string& option) const; 19 | 20 | protected: 21 | std::map m_map; 22 | }; 23 | 24 | template 25 | LineTypeTranslator::LineTypeTranslator(std::map& typeMap) 26 | { 27 | m_map = typeMap; 28 | } 29 | 30 | template 31 | T LineTypeTranslator::LookUp(const std::string& option) const 32 | { 33 | auto enumMapIterator = m_map.find(option); 34 | if (enumMapIterator == m_map.end()) 35 | { 36 | return static_cast(0); 37 | } 38 | 39 | return enumMapIterator->second; 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/PluginSDK/Include/PluginSDK/PluginSDK_NugetVersion.h: -------------------------------------------------------------------------------- 1 | #define PluginSDK_NugetVersion "0.2.0-b55-20160229-172726" 2 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/PluginSDK/Include/PluginSDK/ResourceServer.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | DEFINE_TRACE_AREA(ResourceServer, 0); 15 | 16 | namespace Babylon 17 | { 18 | namespace Transcoder 19 | { 20 | // std::ifstream implementation of Babylon::Transcoder::IResourceServer, which is needed for Import 21 | // Should be constructed with a path that has a trailing slash: '/' or '\\' 22 | class ResourceServer : public Babylon::Transcoder::IResourceServer 23 | { 24 | public: 25 | ResourceServer(std::string baseDirectory) 26 | : m_baseDirectory(std::move(baseDirectory)) 27 | { 28 | } 29 | 30 | virtual std::shared_ptr RequestResource(const std::string& path) const 31 | { 32 | auto relativePath = Babylon::Utils::IsPathRelative(path) ? path : Babylon::Utils::GetPathFileName(path); 33 | auto absolutePath = m_baseDirectory + relativePath; 34 | TRACE_INFO(ResourceServer, "Reading: %s", absolutePath.c_str()); 35 | 36 | auto istream = Babylon::Utils::CreateSharedInputFileStream(absolutePath, std::ios::binary); 37 | if (istream->fail()) 38 | { 39 | TRACE_WARN(ResourceServer, "Failed to read: %s", absolutePath.c_str()); 40 | return nullptr; 41 | } 42 | return istream; 43 | } 44 | private: 45 | std::string m_baseDirectory; 46 | }; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/PluginSDK/Include/PluginSDK/ResourceServerException.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | #include 9 | 10 | namespace Babylon 11 | { 12 | namespace Transcoder 13 | { 14 | struct TranscoderResourceServerException : public 15 | #if FEATURE_TELEMETRYEXCEPTIONSENABLED 16 | Babylon::Utils::BabylonTelemetryException 17 | #else 18 | Babylon::Utils::BabylonException(message, assert) 19 | #endif 20 | { 21 | TranscoderResourceServerException(std::string const& message, bool assert = false) : 22 | Babylon::Utils::BabylonException(message, assert) 23 | {} 24 | 25 | TranscoderResourceServerException(std::string file, int line, std::string const& message, bool assert = false) : 26 | #if FEATURE_TELEMETRYEXCEPTIONSENABLED 27 | Babylon::Utils::BabylonTelemetryException(file, line, message, assert) 28 | {} 29 | #else 30 | Babylon::Utils::BabylonException(message, assert) 31 | { 32 | BabylonUnusedParameter(file); 33 | BabylonUnusedParameter(line); 34 | } 35 | #endif 36 | }; 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/PluginSDK/Include/PluginSDK/TokenParser.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | #include 8 | 9 | namespace Babylon { 10 | // Forward declaration of Vector3, Vector2 11 | namespace Utils 12 | { 13 | namespace Math 14 | { 15 | struct Vector3; 16 | struct Vector2; 17 | } 18 | } 19 | 20 | namespace Transcoder { 21 | 22 | namespace DXSM = Babylon::Utils::Math; 23 | 24 | class TokenParser 25 | { 26 | public: 27 | virtual ~TokenParser(); 28 | static float GetFloatAtPosition(LineTokensPtr const& tokens, size_t position); 29 | static unsigned int GetUnsignedIntAtPosition(LineTokensPtr const& tokens, size_t position); 30 | static DXSM::Vector3 GetVector3AtPosition(LineTokensPtr const& tokens, size_t position); 31 | static DXSM::Vector2 GetVector2AtPosition(LineTokensPtr const& tokens, size_t position); 32 | static DXSM::Vector3 GetVector3AtPositionWithZeroPadding(LineTokensPtr const& tokens, size_t position); 33 | static DXSM::Vector2 GetVector2AtPositionWithZeroPadding(LineTokensPtr const& tokens, size_t position); 34 | static char GetCharAtPosition(LineTokensPtr const& tokens, size_t position); 35 | static bool GetBoolAtPosition(LineTokensPtr const& tokens, size_t position); 36 | 37 | protected: 38 | static void AssertTokensNumber(LineTokensPtr const& tokens, size_t expectedNumberOfTokens); 39 | }; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/PluginSDK/Include/PluginSDK/TranscodeOptions.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | namespace Babylon 14 | { 15 | namespace Transcoder 16 | { 17 | struct TranscodeOption 18 | { 19 | std::string name; 20 | std::string help; 21 | std::function deserializer; 22 | }; 23 | 24 | class TranscodeOptions 25 | { 26 | public: 27 | TranscodeOptions() = default; 28 | virtual ~TranscodeOptions() = default; 29 | void Parse(const std::unordered_map& optionValues); 30 | std::string GenerateHelp() const; 31 | 32 | protected: 33 | void AddOption(TranscodeOption&& option); 34 | 35 | private: 36 | std::unordered_map m_options; 37 | }; 38 | 39 | template 40 | TTranscodeOptions ParseOptions(const std::unordered_map& optionValues) 41 | { 42 | TTranscodeOptions options; 43 | options.Parse(optionValues); 44 | return options; 45 | } 46 | 47 | template 48 | std::string GetHelp() 49 | { 50 | TTranscodeOptions options; 51 | return options.GenerateHelp(); 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/PluginSDK/Source/ExporterBase.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #include "PluginSDKPch.h" 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | using namespace Babylon::Transcoder; 14 | 15 | void ExporterBase::Export(Asset3D& asset) 16 | { 17 | Asset3DTraverser traverser; 18 | traverser.Traverse(*this, asset); 19 | } 20 | 21 | void ExporterBase::ProcessAsset3DBeforeChildren(Asset3D& asset3D) 22 | { 23 | PushTransform(asset3D.GetTransform()); 24 | ExportNodeDownwardPass(asset3D); 25 | } 26 | 27 | void ExporterBase::ProcessAsset3DAfterChildren(Asset3D& asset3D) 28 | { 29 | ExportNodeUpwardPass(asset3D); 30 | PopTransform(); 31 | } 32 | 33 | void ExporterBase::ProcessSceneNodeBeforeChildren(SceneNode& sceneNode) 34 | { 35 | PushTransform(sceneNode.GetTransform()); 36 | ExportNodeDownwardPass(sceneNode); 37 | } 38 | 39 | void ExporterBase::ProcessSceneNodeAfterChildren(SceneNode& sceneNode) 40 | { 41 | ExportNodeUpwardPass(sceneNode); 42 | PopTransform(); 43 | } 44 | 45 | void ExporterBase::ProcessMeshBeforeMaterialAndGeometry(SceneNode& sceneNode, Mesh& mesh) 46 | { 47 | ExportNodeDownwardPass(sceneNode, mesh); 48 | } 49 | 50 | void ExporterBase::ProcessMeshAfterMaterialAndGeometry(SceneNode& sceneNode, Mesh& mesh) 51 | { 52 | ExportNodeUpwardPass(sceneNode, mesh); 53 | } 54 | 55 | void ExporterBase::ProcessMesh(SceneNode&, Mesh& mesh) 56 | { 57 | if(!TestAndSetAlreadyExported(MeshesExported, &mesh)) 58 | { 59 | ExportLeaf(mesh); 60 | } 61 | } 62 | 63 | void ExporterBase::ProcessGeometry(SceneNode&, Mesh&, Geometry& geometry) 64 | { 65 | if(!TestAndSetAlreadyExported(GeometriesExported, &geometry)) 66 | { 67 | ExportLeaf(geometry); 68 | } 69 | } 70 | 71 | void ExporterBase::ProcessMaterial(MaterialDescriptor& material) 72 | { 73 | if(!TestAndSetAlreadyExported(MaterialsExported, &material)) 74 | { 75 | ExportLeaf(material); 76 | } 77 | } 78 | 79 | void ExporterBase::ProcessTexture(TextureDescriptor& texture) 80 | { 81 | if(!TestAndSetAlreadyExported(TexturesExported, &texture)) 82 | { 83 | ExportLeaf(texture); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/PluginSDK/Source/PluginSDKPch.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #include "PluginSDKPch.h" 8 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/PluginSDK/Source/PluginSDKPch.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #ifdef _WIN32 17 | #define WIN32_LEAN_AND_MEAN 18 | #include 19 | #endif 20 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/PluginSDK/Source/TranscodeOptions.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #include "PluginSDKPch.h" 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | DEFINE_TRACE_AREA(TranscodeOptions, 0); 19 | 20 | using namespace Babylon::Transcoder; 21 | 22 | std::string TranscodeOptions::GenerateHelp() const 23 | { 24 | size_t maxOptionLength = 40; // Help options will be tabbed to 40 characters at a minimum 25 | for (const auto& option : m_options) 26 | { 27 | maxOptionLength = std::max(maxOptionLength, option.second.name.length()); 28 | } 29 | 30 | std::stringstream sstr; 31 | for (const auto& option : m_options) 32 | { 33 | sstr << option.second.name << std::string((maxOptionLength - option.second.name.length()) + 4, ' ') << option.second.help << "\n"; 34 | } 35 | return sstr.str(); 36 | } 37 | 38 | void TranscodeOptions::Parse(const std::unordered_map& inputOptions) 39 | { 40 | // For each optionValue (input options, should be a subset of all available options) 41 | for (const auto& inputOption : inputOptions) 42 | { 43 | // Find option using case-insensitive search i.e. inputOption key 'validate' matches m_options['Validate'] 44 | auto option = m_options.find(Utils::ToLower(inputOption.first)); 45 | 46 | if (option != m_options.end()) 47 | { 48 | // Pass the inputOption value in lowercase to the deserializer, i.e. "TRUE" becomes "true" 49 | option->second.deserializer(Utils::ToLower(inputOption.second)); 50 | } 51 | else 52 | { 53 | // Throw an exception if an input option was specified that is not supported 54 | TRACE_WARN(TranscodeOptions, "Unrecognized Transcode option: %s", inputOption.first.c_str()); 55 | } 56 | } 57 | } 58 | 59 | void TranscodeOptions::AddOption(TranscodeOption&& option) 60 | { 61 | auto key = Utils::ToLower(option.name); 62 | m_options.emplace(std::move(key), std::move(option)); 63 | } -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/PluginSDK/Source/TranscoderTextStream.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #include "PluginSDKPch.h" 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | using namespace Babylon::Transcoder; 14 | using namespace Babylon::Utils; 15 | 16 | TranscoderTextStream::TranscoderTextStream(std::shared_ptr stream) 17 | : m_stream(stream), m_size(Babylon::Utils::GetIStreamLength(*stream)) 18 | { 19 | } -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Transcoders 2 | file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS 3 | "Include/*.h" 4 | "Source/*.h" 5 | "Source/*.cpp") 6 | 7 | add_library(Transcoders ${SOURCES}) 8 | 9 | target_include_directories(Transcoders PUBLIC "Include") 10 | target_include_directories(Transcoders PUBLIC "Source") 11 | 12 | set_property(TARGET Transcoders PROPERTY FOLDER Transcoders) 13 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES}) 14 | 15 | target_link_libraries(Transcoders 16 | GLTFSDK 17 | RapidJSON 18 | CoreUtils 19 | Framework 20 | CanvasTex 21 | ImagingComponent 22 | Asset3D 23 | PluginSDK 24 | ) 25 | 26 | if(WIN32 AND SKPSDK_FOUND) 27 | target_link_libraries(Transcoders 28 | SKPSDK 29 | ) 30 | endif() 31 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Include/ExporterGLTF/ExporterGLB.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include "Asset3D/Asset3D.h" 9 | #include "PluginSDK/IOutputStreamFactory.h" 10 | 11 | #include "GLTFSDK/IStreamWriter.h" 12 | 13 | #include "ExporterGLTF/Asset3DToGLTFConverter.h" 14 | #include "ExporterGLTF/GLTFExportOptions.h" 15 | 16 | namespace Babylon 17 | { 18 | namespace Transcoder 19 | { 20 | class ExporterGLB 21 | { 22 | public: 23 | static void ExportStatic(Asset3DPtr asset3D, const std::string& assetName, IOutputStreamFactory* streamFactory, FractionalProgressCallback progress = nullptr, Babylon::Framework::ICancellationTokenPtr cancellationToken = nullptr, const std::unordered_map& options = {}); 24 | 25 | static void Export(const Asset3D& asset3d, std::shared_ptr streamWriter, const std::string& assetName, const GLTFExportOptions& options = {}, Babylon::Framework::ICancellationTokenPtr cancellationToken = nullptr); 26 | }; 27 | 28 | class GLBWriter : public IGLTFWriter 29 | { 30 | public: 31 | GLBWriter(std::string assetName, std::shared_ptr streamWriter); 32 | 33 | void WriteImage(Microsoft::glTF::Document& document, const std::vector& data, 34 | const std::string& id, const std::string& mimeType, const std::string&) override; 35 | 36 | void Finalize(Microsoft::glTF::Document& document, const Microsoft::glTF::ExtensionSerializer& extensionSerializer) override; 37 | 38 | Microsoft::glTF::BufferBuilder& GetBufferBuilder() override { return m_bufferBuilder; } 39 | private: 40 | const std::string m_assetName; 41 | Microsoft::glTF::BufferBuilder m_bufferBuilder; 42 | }; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Include/ExporterGLTF/ExporterGLTF.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include "Asset3D/Asset3D.h" 9 | #include "PluginSDK/IOutputStreamFactory.h" 10 | 11 | #include "GLTFSDK/IStreamWriter.h" 12 | 13 | #include "ExporterGLTF/Asset3DToGLTFConverter.h" 14 | 15 | namespace Babylon 16 | { 17 | namespace Transcoder 18 | { 19 | class GLTFExportOptions; 20 | 21 | class ExporterGLTF 22 | { 23 | public: 24 | static void ExportStatic(Asset3DPtr asset3D, std::string const& assetName, IOutputStreamFactory* streamFactory, FractionalProgressCallback progress = nullptr, Babylon::Framework::ICancellationTokenPtr cancellationToken = nullptr, const std::unordered_map& options = {}); 25 | 26 | static void Export(const Asset3D& asset3d, std::unique_ptr&& streamWriter, const std::string& assetName, const GLTFExportOptions& options, Framework::ICancellationTokenPtr cancellationToken = nullptr); 27 | }; 28 | 29 | class GLTFWriter : public IGLTFWriter 30 | { 31 | public: 32 | GLTFWriter(const std::string& assetName, std::unique_ptr&& streamWriter); 33 | 34 | void WriteImage(Microsoft::glTF::Document& document, const std::vector& data, 35 | const std::string& id, const std::string& mimeType, const std::string& extension) override; 36 | 37 | void Finalize(Microsoft::glTF::Document& document, const Microsoft::glTF::ExtensionSerializer& extensionSerializer) override; 38 | 39 | Microsoft::glTF::BufferBuilder& GetBufferBuilder() override { return m_bufferBuilder; } 40 | private: 41 | const std::string m_assetName; 42 | Microsoft::glTF::BufferBuilder m_bufferBuilder; 43 | }; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Include/ExporterOBJ/ExporterObj.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace Babylon 20 | { 21 | namespace Transcoder 22 | { 23 | class ExporterObj : public ExporterBase 24 | { 25 | public: 26 | static void ExportStatic(Asset3DPtr asset3D, const std::string& assetName, IOutputStreamFactory* streamFactory, FractionalProgressCallback progress = nullptr, Babylon::Framework::ICancellationTokenPtr cancellationToken = nullptr, const std::unordered_map& options = {}); 27 | 28 | ExporterObj(std::string name, IOutputStreamFactory* streamFactory, Babylon::Framework::ICancellationTokenPtr cancellationToken = nullptr); 29 | 30 | virtual void ExportNodeDownwardPass(Asset3D& asset) override; 31 | virtual void ExportNodeDownwardPass(SceneNode& sceneNode) override; 32 | virtual void ExportNodeDownwardPass(SceneNode& sceneNode, Mesh& mesh) override; 33 | virtual void ExportLeaf(MaterialDescriptor& material) override; 34 | 35 | std::string ExportTexture(TextureDescriptor& texture); 36 | 37 | protected: 38 | void WriteVertex(const Geometry& geometry, size_t index); 39 | std::string GetUniqueName(const ITraversableWithName& element); 40 | 41 | std::string m_name; 42 | IOutputStreamFactory* m_streamFactory; 43 | Framework::ICancellationTokenPtr m_cancellationToken; 44 | 45 | std::shared_ptr m_geometryStream; 46 | std::shared_ptr m_materialStream; 47 | 48 | std::unordered_set m_exportedMaterials; 49 | std::unordered_set m_exportedTextures; 50 | 51 | std::unordered_map m_uniqueNames; 52 | }; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Include/ExporterSTL/ExporterAsciiStl.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace Babylon 16 | { 17 | namespace Transcoder 18 | { 19 | class ExporterAsciiStl : public ExporterBase 20 | { 21 | public: 22 | static void ExportStatic(Asset3DPtr asset3D, const std::string& assetName, IOutputStreamFactory* streamFactory, FractionalProgressCallback progress = nullptr, Babylon::Framework::ICancellationTokenPtr cancellationToken = nullptr, const std::unordered_map& options = {}); 23 | 24 | explicit ExporterAsciiStl(std::string assetName, std::ostream& outputStream, Framework::ICancellationTokenPtr cancellationToken = nullptr); 25 | 26 | virtual void ProcessAsset3DBeforeChildren(Asset3D& asset3D) override; 27 | virtual void ProcessAsset3DAfterChildren(Asset3D& asset3D) override; 28 | 29 | virtual void ProcessMeshBeforeMaterialAndGeometry(SceneNode&, Mesh& mesh) override; 30 | 31 | virtual void ProcessSceneNodeBeforeChildren(SceneNode& sceneNode) override; 32 | virtual void ProcessSceneNodeAfterChildren(SceneNode& sceneNode) override; 33 | 34 | ~ExporterAsciiStl() override; 35 | protected: 36 | std::ostream& m_outputStream; 37 | std::string m_assetName; 38 | std::stack m_transforms; 39 | Framework::ICancellationTokenPtr m_cancellationToken; 40 | }; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Include/ExporterTexture/ExporterTexture.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace Babylon 13 | { 14 | namespace Transcoder 15 | { 16 | class ExporterTexture : public ExporterBase 17 | { 18 | public: 19 | enum class TextureType 20 | { 21 | JPG = 0, 22 | PNG = 1 23 | }; 24 | 25 | public: 26 | static void ExportStaticPNG(Asset3DPtr asset3D, std::string const& assetName, IOutputStreamFactory* streamFactory, FractionalProgressCallback progress = nullptr, Babylon::Framework::ICancellationTokenPtr cancellationToken = nullptr, const std::unordered_map& options = {}); 27 | static void ExportStaticJPG(Asset3DPtr asset3D, std::string const& assetName, IOutputStreamFactory* streamFactory, FractionalProgressCallback progress = nullptr, Babylon::Framework::ICancellationTokenPtr cancellationToken = nullptr, const std::unordered_map& options = {}); 28 | explicit ExporterTexture(TextureType typeToExport, 29 | std::map>& textures, 30 | Framework::ICancellationTokenPtr cancellationToken = nullptr); 31 | 32 | virtual void ExportLeaf(MaterialDescriptor& texture) override; 33 | 34 | protected: 35 | void ExportTexture(const TextureDescriptor& texture, const LayerType layer); 36 | 37 | std::string m_extension; 38 | TextureType m_textureType; 39 | std::map>& m_textures; 40 | Framework::ICancellationTokenPtr m_cancellationToken; 41 | }; 42 | } 43 | } -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Include/PluginSKP/PluginSKP.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include 9 | 10 | // Define a macro to enable use of SKP Importer 11 | #if defined(HAS_SKP_LIB) && (CANVAS_PLATFORM_IS_WINDOWS() && defined(_M_X64)) || (CANVAS_PLATFORM_IS_WINRT() && defined(_M_ARM64)) || (CANVAS_PLATFORM_IS_WIN32() && defined(_M_IX86)) 12 | # define CANVAS_CAN_USE_SKP() 1 13 | #else 14 | # define CANVAS_CAN_USE_SKP() 0 15 | #endif 16 | 17 | #if CANVAS_CAN_USE_SKP() 18 | 19 | #include 20 | 21 | #include 22 | 23 | namespace Babylon 24 | { 25 | namespace Transcoder 26 | { 27 | class Asset3D; 28 | class IResourceServer; 29 | 30 | std::shared_ptr ImportSKP( 31 | const std::string& filename, 32 | IResourceServer* resourceServer, 33 | FractionalProgressCallback progress = nullptr, 34 | Babylon::Framework::ICancellationTokenPtr cancellationToken = nullptr, 35 | const std::unordered_map& options = {}, 36 | uint64_t* streamSize = nullptr); 37 | } 38 | } 39 | 40 | #endif -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Include/TranscoderGLTF/GLTFImportOptions.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include 9 | 10 | namespace 11 | { 12 | constexpr const char* kExtractAnimationDataHelp = "Determines whether to enable animation (true|false)"; 13 | constexpr const char* kForceMinecraftBlendMaterialsToMaskHelp = "Determines whether force Minecraft blend materials to mask (true|false)"; 14 | } 15 | 16 | namespace Babylon 17 | { 18 | namespace Transcoder 19 | { 20 | class GLTFImportOptions : public TranscodeOptions 21 | { 22 | public: 23 | GLTFImportOptions() : TranscodeOptions() 24 | { 25 | AddOption({ "ExtractAnimationData", kExtractAnimationDataHelp, 26 | [this](const std::string& value) { SetExtractAnimationData(value); } }); 27 | AddOption({ "ForceMinecraftBlendMaterialsToMask", kForceMinecraftBlendMaterialsToMaskHelp, 28 | [this](const std::string& value) { SetForceMinecraftBlendMaterialsToMask(value); } }); 29 | } 30 | 31 | static GLTFImportOptions ParseOptions(const std::unordered_map& options) 32 | { 33 | return Babylon::Transcoder::ParseOptions(options); 34 | } 35 | 36 | void SetExtractAnimationData(const std::string& value) 37 | { 38 | if (value == "true") { ExtractAnimationData = true; } 39 | else if (value == "false") { ExtractAnimationData = false; } 40 | else { throw Utils::BabylonException("Unrecognized value for 'ExtractAnimationData': " + value); } 41 | } 42 | 43 | void SetForceMinecraftBlendMaterialsToMask(const std::string& value) 44 | { 45 | if (value == "true") { ForceMinecraftBlendMaterialsToMask = true; } 46 | else if (value == "false") { ForceMinecraftBlendMaterialsToMask = false; } 47 | else { throw Utils::BabylonException("Unrecognized value for 'ForceMinecraftBlendMaterialsToMask': " + value); } 48 | } 49 | 50 | bool ExtractAnimationData = true; 51 | bool ForceMinecraftBlendMaterialsToMask = false; 52 | }; 53 | } 54 | } -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Include/TranscoderGLTF/IStreamReaderRSAdapter.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include "GLTFSDK/IStreamReader.h" 9 | 10 | #include 11 | #include "TranscoderException.h" 12 | 13 | namespace Babylon 14 | { 15 | namespace Transcoder 16 | { 17 | class IStreamReaderRSAdapter : public Microsoft::glTF::IStreamReader 18 | { 19 | public: 20 | IStreamReaderRSAdapter(IResourceServer* resourceServer) 21 | : m_resourceServer(resourceServer) 22 | { 23 | } 24 | 25 | std::shared_ptr GetInputStream(const std::string& filename) const override 26 | { 27 | std::shared_ptr stream; 28 | try 29 | { 30 | stream = m_resourceServer->RequestResource(filename); 31 | } 32 | catch (const std::exception& ex) 33 | { 34 | throw TranscoderResourceFailedException(ex.what()); 35 | } 36 | 37 | if (stream == nullptr) 38 | { 39 | throw TranscoderResourceFailedException("resource not found or empty. " + filename); 40 | } 41 | 42 | return stream; 43 | } 44 | 45 | private: 46 | IResourceServer* const m_resourceServer; 47 | }; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Include/TranscoderGLTF/IStreamWriterOSFAdapter.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #include "GLTFSDK/IStreamWriter.h" 8 | 9 | #include 10 | 11 | namespace Babylon 12 | { 13 | namespace Transcoder 14 | { 15 | class IStreamWriterOSFAdapter : public Microsoft::glTF::IStreamWriter 16 | { 17 | public: 18 | IStreamWriterOSFAdapter(IOutputStreamFactory& outputStreamFactory) 19 | : m_outputStreamFactory(outputStreamFactory) 20 | { 21 | } 22 | 23 | std::shared_ptr GetOutputStream(const std::string& filename) const override 24 | { 25 | return m_outputStreamFactory.CreateStream(filename); 26 | } 27 | 28 | private: 29 | IOutputStreamFactory& m_outputStreamFactory; 30 | }; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Include/TranscoderGLTF/ImporterGLB.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include "Asset3D/Asset3D.h" 9 | #include "GLTFSDK/GLBResourceReader.h" 10 | 11 | namespace Babylon 12 | { 13 | namespace Transcoder 14 | { 15 | class ImporterGLB 16 | { 17 | public: 18 | static std::shared_ptr Import( 19 | const std::shared_ptr& streamReader, 20 | std::shared_ptr glbStream, 21 | Framework::ICancellationTokenPtr cancellationToken, 22 | const std::unordered_map& options); 23 | }; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Include/TranscoderGLTF/ImporterGLTF.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include 9 | #include "GLTFSDK/IStreamReader.h" 10 | 11 | namespace Babylon 12 | { 13 | namespace Transcoder 14 | { 15 | class GLTFImportOptions; 16 | 17 | class ImporterGLTF 18 | { 19 | public: 20 | static std::shared_ptr Import( 21 | const std::shared_ptr& resourceReader, 22 | std::shared_ptr stream, 23 | Framework::ICancellationTokenPtr cancellationToken, 24 | const GLTFImportOptions& options); 25 | 26 | private: 27 | static std::string ParseJson(std::istream& stream); 28 | }; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Include/TranscoderGLTF/StringUtils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace Babylon 7 | { 8 | namespace Transcoder 9 | { 10 | namespace GLTF 11 | { 12 | class StringUtils 13 | { 14 | public: 15 | 16 | static std::string RemoveAllWhiteSpaces(std::string str) 17 | { 18 | std::string::iterator end_pos = std::remove(str.begin(), str.end(), ' '); 19 | str.erase(end_pos, str.end()); 20 | return str; 21 | } 22 | }; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Include/TranscoderGLTF/TranscoderGLB.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include 9 | 10 | namespace Babylon 11 | { 12 | namespace Transcoder 13 | { 14 | class Asset3D; 15 | class IResourceServer; 16 | 17 | std::shared_ptr ImportGLB(const std::string& filename, IResourceServer* resourceServer, FractionalProgressCallback progress = nullptr, Babylon::Framework::ICancellationTokenPtr cancellationToken = nullptr, const std::unordered_map& options = {}, uint64_t* streamSize = nullptr); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Include/TranscoderGLTF/TranscoderGLTF.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include 9 | 10 | #include 11 | 12 | namespace Babylon 13 | { 14 | namespace Transcoder 15 | { 16 | class Asset3D; 17 | class IResourceServer; 18 | 19 | std::shared_ptr ImportGLTF(const std::string& filename, IResourceServer* resourceServer, FractionalProgressCallback progress = nullptr, Babylon::Framework::ICancellationTokenPtr cancellationToken = nullptr, const std::unordered_map& options = {}, uint64_t* streamSize = nullptr); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Include/TranscoderGLTF/TransformMatrixUtils.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | using namespace Babylon::Utils::Math; 13 | 14 | namespace Babylon 15 | { 16 | namespace Transcoder 17 | { 18 | class TransformMatrixUtils 19 | { 20 | public: 21 | static Matrix CreateTransformationMatrix(const Microsoft::glTF::Vector3& scale, const Microsoft::glTF::Vector3& translation, const Microsoft::glTF::Quaternion& rotation) 22 | { 23 | Matrix scaleMatrix(Matrix::CreateScale(scale.x, scale.y, scale.z)); 24 | Matrix translateMatrix(Matrix::CreateTranslation(translation.x, translation.y, translation.z)); 25 | Matrix rotationMatrix(Matrix::CreateFromQuaternion(Utils::Math::Quaternion(rotation.x, rotation.y, rotation.z, rotation.w))); 26 | 27 | // GLTF 2.0 requires scale to be applied first, then rotation, then translation 28 | return scaleMatrix * rotationMatrix * translateMatrix; 29 | } 30 | }; 31 | } 32 | } -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Include/TranscoderOBJ/AuthorType.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | namespace Babylon { 9 | namespace Transcoder { 10 | enum AuthorType 11 | { 12 | unknownAuthor = 0, 13 | autodesk123D = 1, 14 | blender, 15 | }; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Include/TranscoderOBJ/GeometryLineType.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | namespace Babylon { 9 | namespace Transcoder { 10 | enum GeometryLineType 11 | { 12 | v = 1, 13 | vt, 14 | vn, 15 | f, 16 | SmoothingGroupLine, 17 | mtllib, 18 | usemtl, 19 | comment, 20 | }; 21 | } 22 | } -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Include/TranscoderOBJ/MtlLineType.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | namespace Babylon { 9 | namespace Transcoder { 10 | enum class MtlLineType 11 | { 12 | newmtl = 1, 13 | 14 | // Texture maps 15 | TextureDiffuse = 2, 16 | TextureSpecular, 17 | TextureEmissive, 18 | TextureNormal, 19 | TextureDetail, 20 | 21 | // Material Color and illumination statements 22 | ColorDiffuse, 23 | Opacity, 24 | ColorSpecular, 25 | SpecularExponent, 26 | 27 | // Not supported lines 28 | //map_Ns, // Specular 29 | //disp, // Scalar texture used to deform the surface 30 | //decal, // Scalar {"", procedural texture} file texture used to replace the material color with the texture color 31 | //refl, 32 | //Ni, // Optical density 33 | //d, // Dissolve 34 | //illum, // Illumination Model 35 | //Tf, // Transmission Filter 36 | //sharpness, // Sharpness of Reflections 37 | }; 38 | } 39 | } -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Include/TranscoderOBJ/MtlTextureMapOptions.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | namespace Babylon { 8 | namespace Transcoder { 9 | enum MtlTextureMapOptions 10 | { 11 | NotASupportedOption = 0, 12 | blendu, 13 | blendv, 14 | clamp, 15 | o, 16 | s, 17 | t, 18 | mm, 19 | cc, 20 | boost, 21 | texres, 22 | bm, 23 | imfchan, 24 | }; 25 | } 26 | } -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Include/TranscoderOBJ/TranscoderOBJ.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | namespace Babylon 9 | { 10 | namespace Transcoder 11 | { 12 | class Asset3D; 13 | 14 | std::shared_ptr ImportOBJ(const std::string& filename, IResourceServer* resourceServer, FractionalProgressCallback progress = nullptr, Babylon::Framework::ICancellationTokenPtr cancellationToken = nullptr, const std::unordered_map& options = {}, uint64_t* streamSize = nullptr); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Include/TranscoderPLY/TranscoderPLY.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include 9 | 10 | namespace Babylon 11 | { 12 | namespace Transcoder 13 | { 14 | class Asset3D; 15 | 16 | std::shared_ptr ImportPLY(const std::string& filename, IResourceServer* resourceServer, FractionalProgressCallback progress = nullptr, Babylon::Framework::ICancellationTokenPtr cancellationToken = nullptr, const std::unordered_map& options = {}, uint64_t* streamSize = nullptr); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Include/TranscoderSTL/StlAsciiParser.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | namespace Babylon 15 | { 16 | namespace Transcoder 17 | { 18 | class StlAsciiParser : public Transcoder::FileParserBase 19 | { 20 | public: 21 | enum class LineType 22 | { 23 | Unknown = 0, 24 | Solid, 25 | Facet, 26 | OuterLoop, 27 | Vertex, 28 | EndLoop, 29 | EndFacet, 30 | EndSolid, 31 | }; 32 | 33 | StlAsciiParser(IResourceServer& resourceServer, UpdateReporter* updateReporter, Framework::ICancellationTokenPtr cancellationToken = nullptr); 34 | 35 | void ProcessNonEmptyLine(Transcoder::LineTokensPtr& tokens) override; 36 | void FinalizeParseStream(void) override; 37 | 38 | inline std::shared_ptr GetAsset3D() const { return m_asset3D; } 39 | 40 | private: 41 | static const LineTypeTranslator m_lineTypeTranslator; 42 | 43 | void ParseSolid(const Transcoder::LineTokensPtr& tokens); 44 | void ParseFacet(const Transcoder::LineTokensPtr& tokens); 45 | void ParseOuterLoop(const Transcoder::LineTokensPtr& tokens); 46 | void ParseVertex(const Transcoder::LineTokensPtr& tokens); 47 | 48 | void ParseEndLoop(const Transcoder::LineTokensPtr& tokens); 49 | 50 | void CheckAndPush(LineType current, LineType parent, const std::string& message); 51 | void CheckAndPop(LineType sibling, const std::string& message, const Babylon::Transcoder::LineTokensPtr& tokens); 52 | 53 | std::shared_ptr m_asset3D; 54 | 55 | std::vector m_indices; 56 | std::vector m_positions; 57 | 58 | std::stack m_hierarchy; 59 | 60 | Framework::ICancellationTokenPtr m_cancellationToken; 61 | }; 62 | } 63 | } -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Include/TranscoderSTL/StlBinaryParser.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include 9 | 10 | namespace Babylon 11 | { 12 | namespace Transcoder 13 | { 14 | class Asset3D; 15 | class UpdateReporter; 16 | 17 | typedef std::function PercentageCompleteCallback; 18 | 19 | class StlBinaryParser : public IParser 20 | { 21 | public: 22 | StlBinaryParser(IResourceServer& resourceServer, UpdateReporter* updateReporter, Framework::ICancellationTokenPtr cancellationToken = nullptr); 23 | ~StlBinaryParser(); 24 | 25 | std::shared_ptr ParseStream(std::shared_ptr stream); 26 | 27 | protected: 28 | static inline Babylon::Utils::Math::Vector3 FlipYZAxis(Babylon::Utils::Math::Vector3 position); 29 | private: 30 | Geometry ReadGeometry(std::shared_ptr stream, uint32_t triangleCount); 31 | 32 | UpdateReporter* m_updateReporter; 33 | Framework::ICancellationTokenPtr m_cancellationToken; 34 | }; 35 | } 36 | } 37 | 38 | inline Babylon::Utils::Math::Vector3 Babylon::Transcoder::StlBinaryParser::FlipYZAxis( 39 | Babylon::Utils::Math::Vector3 position) 40 | { 41 | return Babylon::Utils::Math::Vector3(position.x, position.z, -position.y); 42 | } 43 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Include/TranscoderSTL/TranscoderSTL.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include 9 | #include 10 | 11 | namespace Babylon 12 | { 13 | namespace Transcoder 14 | { 15 | class Asset3D; 16 | 17 | enum class StlFileType 18 | { 19 | Ascii, 20 | Binary, 21 | Unknown 22 | }; 23 | 24 | std::shared_ptr ImportSTL(const std::string& filename, IResourceServer* resourceServer, FractionalProgressCallback progress = nullptr, Babylon::Framework::ICancellationTokenPtr cancellationToken = nullptr, const std::unordered_map& options = {}, uint64_t* streamSize = nullptr); 25 | 26 | StlFileType GetStlFileType(std::shared_ptr stream); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Source/TranscoderException.cpp: -------------------------------------------------------------------------------- 1 | #include "TranscodersPch.h" 2 | #include 3 | #include 4 | 5 | 6 | #undef TranscoderException 7 | 8 | namespace Babylon 9 | { 10 | namespace Transcoder 11 | { 12 | 13 | TranscoderException::TranscoderException(std::string const& message, bool assert) : 14 | Babylon::Utils::BabylonException(message, assert) 15 | {} 16 | 17 | TranscoderException::TranscoderException(std::string file, int line, std::string const& message, bool assert) : 18 | #if FEATURE_TELEMETRYEXCEPTIONSENABLED 19 | Babylon::Utils::BabylonTelemetryException(file, line, "Hardware Version: " + Babylon::Engine::g_hardwareVersion + "Error Message: " + message, assert) 20 | {} 21 | #else 22 | TranscoderException(message, assert) 23 | { 24 | BabylonUnusedParameter(file); 25 | BabylonUnusedParameter(line); 26 | } 27 | #endif 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Source/TranscoderGLTF/ImporterGLB.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #include "TranscodersPch.h" 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | #include "TranscoderGLTF/GLTFToAsset3DConverter.h" 18 | #include "TranscoderGLTF/ImporterGLB.h" 19 | #include "TranscoderGLTF/GLTFImportOptions.h" 20 | 21 | using namespace Microsoft; 22 | using namespace Babylon::Utils; 23 | using namespace Babylon::Transcoder; 24 | 25 | DEFINE_TRACE_AREA(ImporterGLB, 0); 26 | 27 | std::shared_ptr ImporterGLB::Import( 28 | const std::shared_ptr& streamReader, 29 | std::shared_ptr glbStream, 30 | Babylon::Framework::ICancellationTokenPtr cancellationToken, 31 | const std::unordered_map& options) 32 | { 33 | if (cancellationToken == nullptr) 34 | { 35 | cancellationToken = Babylon::Framework::MakeNullCancellationToken(); 36 | } 37 | 38 | Microsoft::glTF::GLBResourceReader resourceReader(streamReader, glbStream); 39 | auto json = resourceReader.GetJson(); 40 | 41 | cancellationToken->CheckCancelledAndThrow(); 42 | 43 | auto doc = Microsoft::glTF::Deserialize(json, Microsoft::glTF::KHR::GetKHRExtensionDeserializer(), Microsoft::glTF::DeserializeFlags::IgnoreByteOrderMark); 44 | Microsoft::glTF::Validation::Validate(doc); 45 | 46 | cancellationToken->CheckCancelledAndThrow(); 47 | 48 | GLTF::GLTFToAsset3DConverter converter(resourceReader, GLTFImportOptions::ParseOptions(options)); 49 | return converter.CreateAsset3D(doc, cancellationToken); 50 | } -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Source/TranscoderGLTF/ImporterGLTF.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #include "TranscodersPch.h" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | #include "TranscoderGLTF/GLTFToAsset3DConverter.h" 16 | #include "TranscoderGLTF/ImporterGLTF.h" 17 | #include "TranscoderGLTF/GLTFImportOptions.h" 18 | 19 | using namespace Microsoft; 20 | using namespace Babylon::Transcoder; 21 | using namespace Babylon::Transcoder::GLTF; 22 | 23 | std::shared_ptr ImporterGLTF::Import( 24 | const std::shared_ptr& streamReader, 25 | std::shared_ptr stream, 26 | Babylon::Framework::ICancellationTokenPtr cancellationToken, 27 | const GLTFImportOptions& options) 28 | { 29 | if (cancellationToken == nullptr) 30 | { 31 | cancellationToken = Babylon::Framework::MakeNullCancellationToken(); 32 | } 33 | 34 | glTF::GLTFResourceReader resourceReader(streamReader); 35 | 36 | cancellationToken->CheckCancelledAndThrow(); 37 | 38 | auto json = ImporterGLTF::ParseJson(*stream); 39 | auto doc = glTF::Deserialize(json, glTF::KHR::GetKHRExtensionDeserializer(), glTF::DeserializeFlags::IgnoreByteOrderMark); 40 | glTF::Validation::Validate(doc); 41 | 42 | cancellationToken->CheckCancelledAndThrow(); 43 | 44 | GLTFToAsset3DConverter converter(resourceReader, options); 45 | return converter.CreateAsset3D(doc, cancellationToken); 46 | } 47 | 48 | std::string ImporterGLTF::ParseJson(std::istream& stream) 49 | { 50 | auto dq = Babylon::Utils::ConvertStreamToDeque(stream); 51 | 52 | //Copy deque into string after we reserve memory to prevent growing the string. 53 | std::string s; 54 | s.reserve(dq.size()); 55 | s.assign(dq.begin(), dq.end()); 56 | 57 | return s; 58 | } -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Source/TranscoderGLTF/TranscoderGLB.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #include "TranscodersPch.h" 7 | 8 | #include 9 | 10 | #include "TranscoderException.h" 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | using namespace Babylon::Transcoder; 19 | using namespace Babylon::Utils; 20 | using namespace GLTF; 21 | 22 | std::shared_ptr Babylon::Transcoder::ImportGLB( 23 | const std::string& filename, 24 | IResourceServer* resourceServer, 25 | FractionalProgressCallback progress, 26 | Babylon::Framework::ICancellationTokenPtr cancellationToken, 27 | const std::unordered_map& options, 28 | uint64_t* streamSize) 29 | { 30 | std::shared_ptr asset3d; 31 | 32 | auto istream = resourceServer->RequestResource(filename); 33 | if (istream == nullptr) 34 | { 35 | throw TranscoderResourceFailedException(filename); 36 | } 37 | 38 | if (streamSize != nullptr) 39 | { 40 | *streamSize = Babylon::Utils::GetIStreamLength(*istream); 41 | } 42 | 43 | try 44 | { 45 | auto streamReader = std::make_shared(resourceServer); 46 | asset3d = ImporterGLB::Import(streamReader, istream, cancellationToken, options); 47 | } 48 | catch (Microsoft::glTF::GLTFException ex) 49 | { 50 | throw BabylonException(ex.what()); 51 | } 52 | 53 | return asset3d; 54 | } -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Source/TranscoderGLTF/TranscoderGLTF.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #include "TranscodersPch.h" 7 | 8 | #include 9 | 10 | #include "TranscoderException.h" 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include "TranscoderGLTF/IStreamReaderRSAdapter.h" 19 | #include "TranscoderGLTF/GLTFImportOptions.h" 20 | 21 | using namespace Babylon::Transcoder; 22 | using namespace Babylon::Utils; 23 | using namespace GLTF; 24 | 25 | std::shared_ptr Babylon::Transcoder::ImportGLTF( 26 | const std::string& filename, 27 | IResourceServer* resourceServer, 28 | FractionalProgressCallback progress, 29 | Babylon::Framework::ICancellationTokenPtr cancellationToken, 30 | const std::unordered_map& options, 31 | uint64_t* streamSize) 32 | { 33 | auto stream = resourceServer->RequestResource(filename); 34 | if (stream == nullptr) 35 | { 36 | throw TranscoderResourceFailedException("resource not found or empty. " + filename); 37 | } 38 | 39 | if (streamSize != nullptr) 40 | { 41 | *streamSize = Babylon::Utils::GetIStreamLength(*stream); 42 | } 43 | 44 | try 45 | { 46 | auto streamReader = std::make_shared(resourceServer); 47 | auto asset3d = ImporterGLTF::Import(streamReader, stream, cancellationToken, GLTFImportOptions::ParseOptions(options)); 48 | return asset3d; 49 | } 50 | catch (Microsoft::glTF::GLTFException ex) 51 | { 52 | throw BabylonException(ex.what()); 53 | } 54 | } -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Source/TranscoderOBJ/TranscoderOBJ.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #include "TranscodersPch.h" 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include "TranscoderException.h" 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | using namespace Babylon::Transcoder; 21 | 22 | std::shared_ptr Babylon::Transcoder::ImportOBJ(const std::string& filename, IResourceServer* resourceServer, FractionalProgressCallback progress, Babylon::Framework::ICancellationTokenPtr cancellationToken, const std::unordered_map& options, uint64_t* streamSize) 23 | { 24 | TranscodeOptions transcodeOptions; 25 | transcodeOptions.Parse(options); 26 | 27 | auto istream = resourceServer->RequestTextFileResource(filename); 28 | if (istream == nullptr) 29 | { 30 | throw TranscoderResourceFailedException("resource not found or empty. " + filename); 31 | } 32 | 33 | if (streamSize != nullptr) 34 | { 35 | *streamSize = istream->GetSize(); 36 | } 37 | 38 | UpdateReporter percentageReporter; 39 | percentageReporter.SetProgressReporter(progress); 40 | 41 | auto fileParser = std::make_unique(*resourceServer, &percentageReporter, cancellationToken); 42 | // MPJ TODO: Need to handle load options in a nice way (e.g. JSON would make extensible, data-driven configurations much easier in future) 43 | fileParser->ParseStream(istream); 44 | 45 | return fileParser->GetAsset3D(); 46 | } -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Source/TranscoderPLY/TranscoderPLY.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #include "TranscodersPch.h" 8 | 9 | #include "TranscoderException.h" 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | DEFINE_TRACE_AREA(TranscoderPLY, 0); 22 | 23 | using namespace Babylon::Transcoder; 24 | 25 | std::shared_ptr Babylon::Transcoder::ImportPLY( 26 | const std::string& filename, 27 | IResourceServer* resourceServer, 28 | FractionalProgressCallback progress, 29 | Babylon::Framework::ICancellationTokenPtr cancellationToken, 30 | const std::unordered_map& options, 31 | uint64_t* streamSize) 32 | { 33 | TranscodeOptions transcodeOptions; 34 | transcodeOptions.Parse(options); 35 | 36 | auto stream = resourceServer->RequestTextFileResource(filename); 37 | if (stream == nullptr) 38 | { 39 | throw TranscoderResourceFailedException("resource not found or empty. " + filename); 40 | } 41 | 42 | if (streamSize != nullptr) 43 | { 44 | *streamSize = stream->GetSize(); 45 | } 46 | 47 | PLYParser fileParser(stream, resourceServer, progress, cancellationToken); 48 | 49 | fileParser.ParseStreamToPly(); 50 | 51 | //release the stream as soon as possible 52 | stream.reset(); 53 | 54 | return fileParser.CreateAsset3d(); 55 | } 56 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Source/TranscoderSKP/PluginSKP.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #include "TranscodersPch.h" 7 | 8 | #include 9 | #include 10 | 11 | #if CANVAS_CAN_USE_SKP() 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | #include "ImporterSKP.h" 18 | #include "TranscoderException.h" 19 | 20 | #include 21 | 22 | using namespace Babylon::Transcoder; 23 | 24 | std::shared_ptr Babylon::Transcoder::ImportSKP( 25 | const std::string& filename, 26 | IResourceServer* resourceServer, 27 | FractionalProgressCallback progress, 28 | Babylon::Framework::ICancellationTokenPtr cancellationToken, 29 | const std::unordered_map& /*options*/, 30 | uint64_t* streamSize) 31 | { 32 | auto stream = resourceServer->RequestResource(filename); 33 | if (stream == nullptr) 34 | { 35 | throw TranscoderResourceFailedException("resource not found or empty. " + filename); 36 | } 37 | 38 | if (streamSize != nullptr) 39 | { 40 | *streamSize = Babylon::Utils::GetIStreamLength(*stream); 41 | } 42 | 43 | UpdateReporter percentageReporter; 44 | percentageReporter.SetProgressReporter(progress); 45 | percentageReporter.SetWeights(1.0f, 0.0f); 46 | 47 | if (cancellationToken == nullptr) 48 | { 49 | cancellationToken = Babylon::Framework::MakeNullCancellationToken(); 50 | } 51 | 52 | ImporterSKP importer; 53 | auto asset3d = importer.ImportToAsset3D(stream, &percentageReporter, cancellationToken); 54 | 55 | return asset3d; 56 | } 57 | 58 | #endif -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Source/TranscodersPch.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #include "TranscodersPch.h" 8 | -------------------------------------------------------------------------------- /Morphs/Importers/Transcoders/Transcoders/Source/TranscodersPch.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #define BABYLON_SDK_API 10 | 11 | #define WIN32_LEAN_AND_MEAN 12 | #define _ATL_NO_WIN_SUPPORT 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include 39 | 40 | #include 41 | 42 | #ifdef _WIN32 43 | #include 44 | #endif 45 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/Asset3D/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Asset3D 2 | file(GLOB SOURCES CONFIGURE_DEPENDS 3 | "Include/Asset3D/*.h" 4 | "Source/*.h" 5 | "Source/*.cpp") 6 | 7 | add_library(Asset3D ${SOURCES}) 8 | 9 | target_include_directories(Asset3D PUBLIC "Include") 10 | 11 | set_property(TARGET Asset3D PROPERTY FOLDER Utils) 12 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES}) 13 | 14 | target_link_libraries(Asset3D 15 | CoreUtils 16 | Framework 17 | ImagingComponent 18 | ) 19 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/Asset3D/Include/Asset3D/Asset3DTraverser.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | namespace Babylon 10 | { 11 | namespace Transcoder 12 | { 13 | class IAsset3DProcessor; 14 | class Asset3D; 15 | class SceneNode; 16 | class Mesh; 17 | 18 | class Asset3DTraverser 19 | { 20 | public: 21 | void Traverse(IAsset3DProcessor& processor, Asset3D& asset3d); 22 | 23 | void Traverse(IAsset3DProcessor& processor, SceneNode& sceneNode); 24 | 25 | void Traverse(IAsset3DProcessor& processor, SceneNode& sceneNode, Mesh& mesh); 26 | 27 | size_t GetDepth() const; 28 | 29 | private: 30 | size_t m_depth = 0; 31 | }; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/Asset3D/Include/Asset3D/Camera.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include "Asset3D/ITraversable.h" 9 | #include 10 | #include "Projection.h" 11 | 12 | namespace Babylon 13 | { 14 | namespace Transcoder 15 | { 16 | class Camera : public ITraversableWithName 17 | { 18 | public: 19 | Camera(std::unique_ptr&& projection) : 20 | ITraversableWithName(), m_projection(std::move(projection)) 21 | { 22 | } 23 | 24 | Camera(const Camera& c) : 25 | ITraversableWithName(), 26 | m_projection(c.m_projection->Clone()) 27 | { 28 | } 29 | 30 | const Perspective& GetPerspective() const 31 | { 32 | if (auto ret = dynamic_cast(m_projection.get())) 33 | { 34 | return *ret; 35 | } 36 | throw Babylon::Utils::BabylonException("Projection is not perspective"); 37 | } 38 | 39 | const Orthographic& GetOrthographic() const 40 | { 41 | if (auto ret = dynamic_cast(m_projection.get())) 42 | { 43 | return *ret; 44 | } 45 | throw Babylon::Utils::BabylonException("Projection is not orthographic"); 46 | } 47 | 48 | ProjectionType GetProjectionType() const 49 | { 50 | return m_projection->GetProjectionType(); 51 | } 52 | 53 | private: 54 | std::unique_ptr m_projection; 55 | }; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/Asset3D/Include/Asset3D/ExtensionsPayloadData.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | #include 8 | 9 | namespace Babylon 10 | { 11 | namespace Transcoder 12 | { 13 | class ExtensionsPayloadData 14 | { 15 | // ExtensionsPayloadData contains a map of maps; 16 | // Each map (PayloadMap) has all extensions stored in a particular glTF property, e.g. mesh, node 17 | // Each extension (ExtensionMap) in this glTF property is stored as a mapping from a string key or name to a string value 18 | public: 19 | using PayloadStr = std::shared_ptr; 20 | 21 | struct ExtensionMapStruct { 22 | std::map ExtensionMap; 23 | }; 24 | 25 | struct PayloadMapStruct { 26 | std::map PayloadMap; 27 | }; 28 | 29 | inline void AddItem(const std::string& key, const std::string& extensionKey, const std::string& extensionValue) 30 | { 31 | if (!key.empty() && !extensionKey.empty() && !extensionValue.empty()) 32 | { 33 | m_extensionsPayloadMap.PayloadMap[key].ExtensionMap[extensionKey] = 34 | std::make_shared(extensionValue); 35 | } 36 | } 37 | 38 | // Retrieve all extensions of a node, mesh etc, as a map 39 | inline ExtensionMapStruct GetExtensions(const std::string& key) const 40 | { 41 | auto it = m_extensionsPayloadMap.PayloadMap.find(key); 42 | if (it == m_extensionsPayloadMap.PayloadMap.end()) 43 | { 44 | return ExtensionMapStruct(); 45 | } 46 | return it->second; 47 | } 48 | 49 | // Retrieve specific extension of a node, mesh, etc 50 | inline PayloadStr GetExtension(const std::string& key, const std::string& extensionKey) const 51 | { 52 | ExtensionMapStruct extensions = GetExtensions(key); 53 | auto it = extensions.ExtensionMap.find(extensionKey); 54 | if (it == extensions.ExtensionMap.end()) 55 | { 56 | return PayloadStr(); 57 | } 58 | return it->second; 59 | } 60 | 61 | private: 62 | PayloadMapStruct m_extensionsPayloadMap; 63 | }; 64 | } 65 | } -------------------------------------------------------------------------------- /Morphs/Importers/Utils/Asset3D/Include/Asset3D/MaterialConversionUtils.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | namespace Babylon 14 | { 15 | namespace Transcoder 16 | { 17 | struct AlbedoWorkflowPair 18 | { 19 | std::shared_ptr Albedo; 20 | std::shared_ptr Workflow; 21 | }; 22 | 23 | namespace MaterialConversionUtils 24 | { 25 | AlbedoWorkflowPair SpecGlossToMetalRough(const std::shared_ptr& diffuseLayer, const std::shared_ptr& specGlossLayer); 26 | AlbedoWorkflowPair MetalRoughToSpecGloss(const std::shared_ptr& baseColorLayer, const std::shared_ptr& metalRoughLayer); 27 | 28 | void GenerateLegacyGlossiness(BGRAImage& bgra); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Morphs/Importers/Utils/Asset3D/Include/Asset3D/Projection.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include 9 | 10 | #include 11 | 12 | namespace Babylon 13 | { 14 | namespace Transcoder 15 | { 16 | enum class ProjectionType 17 | { 18 | kPerspective, 19 | kOrthographic 20 | }; 21 | 22 | class Projection 23 | { 24 | public: 25 | virtual ~Projection() = default; 26 | 27 | virtual ProjectionType GetProjectionType() const = 0; 28 | virtual std::unique_ptr Clone() const = 0; 29 | }; 30 | 31 | class Perspective : public Projection 32 | { 33 | public: 34 | Perspective(float znear, float yfov) : 35 | znear(znear), 36 | yfov(yfov) 37 | { 38 | } 39 | 40 | virtual ProjectionType GetProjectionType() const 41 | { 42 | return ProjectionType::kPerspective; 43 | } 44 | 45 | virtual std::unique_ptr Clone() const 46 | { 47 | return std::make_unique(*this); 48 | } 49 | 50 | Utils::Optional zfar; 51 | float znear; 52 | Utils::Optional aspectRatio; 53 | float yfov; 54 | }; 55 | 56 | class Orthographic : public Projection 57 | { 58 | public: 59 | Orthographic(float zfar, float znear, float xmag, float ymag) : 60 | zfar(zfar), 61 | znear(znear), 62 | xmag(xmag), 63 | ymag(ymag) 64 | { 65 | } 66 | 67 | virtual ProjectionType GetProjectionType() const 68 | { 69 | return ProjectionType::kOrthographic; 70 | } 71 | 72 | virtual std::unique_ptr Clone() const 73 | { 74 | return std::make_unique(*this); 75 | } 76 | 77 | float zfar; 78 | float znear; 79 | float xmag; 80 | float ymag; 81 | }; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/Asset3D/Include/Asset3D/TexturePackingUtils.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | namespace Babylon 9 | { 10 | namespace Transcoder 11 | { 12 | struct MaterialLayer; 13 | 14 | namespace TexturePackingUtils 15 | { 16 | std::shared_ptr PackNormalRoughnessMetallic(const std::shared_ptr& normalLayer, const std::shared_ptr& metalRoughLayer); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /Morphs/Importers/Utils/Asset3D/Source/Asset3D.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #include "Asset3DPch.h" 7 | 8 | #include 9 | 10 | DEFINE_TRACE_AREA(Asset3D_Root, 0); 11 | 12 | namespace Babylon 13 | { 14 | namespace Transcoder 15 | { 16 | Asset3D::Asset3D() : SceneNode() 17 | { 18 | SetName("root"); 19 | } 20 | 21 | BoundingBox Asset3D::CalcTopDownBounds(const Babylon::Utils::Math::Matrix& transform) const 22 | { 23 | BoundingBox box; 24 | Utils::Math::Matrix ourTransform = GetTransform() * transform; 25 | for (auto child : m_children) 26 | { 27 | box.Update(child->CalcTopDownBounds(ourTransform)); 28 | } 29 | 30 | if (HasMesh()) 31 | { 32 | box.Update(m_mesh->CalcTopDownBounds(ourTransform)); 33 | } 34 | return box; 35 | } 36 | 37 | float Asset3D::CalculateConversionScale(UnitInCentimeter origUnit, UnitInCentimeter destUnit) 38 | { 39 | assert(origUnit != SYSTEMUNIT_NONE && destUnit != SYSTEMUNIT_NONE); 40 | return origUnit / destUnit; 41 | } 42 | 43 | Utils::Math::Matrix Asset3D::GetUnitScaledTransform(UnitInCentimeter unit) const 44 | { 45 | // If there's no unit information, we can't scale to a different unit *OR* 46 | // if the asset is already the desired unit, just return the transform 47 | if (m_systemUnit == SYSTEMUNIT_NONE || 48 | m_systemUnit == unit) 49 | { 50 | return m_transform; 51 | } 52 | 53 | // Otherwise convert from the asset's unit to the desired unit 54 | float scale = Asset3D::CalculateConversionScale(m_systemUnit, unit); 55 | auto scaleMatrix = Utils::Math::Matrix::CreateScale(scale); 56 | auto scaledTransform = m_transform * scaleMatrix; 57 | return scaledTransform; 58 | } 59 | } // namespace Transcoder 60 | } // namespace Babylon 61 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/Asset3D/Source/Asset3DPch.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #include "Asset3DPch.h" 8 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/Asset3D/Source/Asset3DPch.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/Asset3D/Source/Asset3DTraverser.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #include "Asset3DPch.h" 7 | 8 | #include 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | void Babylon::Transcoder::Asset3DTraverser::Traverse(IAsset3DProcessor& processor, Asset3D& asset3d) 20 | { 21 | processor.ProcessAsset3DBeforeChildren(asset3d); 22 | 23 | for (auto& child : asset3d.GetChildren()) 24 | { 25 | m_depth++; 26 | Traverse(processor, *child); 27 | m_depth--; 28 | } 29 | 30 | if (asset3d.HasMesh()) 31 | { 32 | Traverse(processor, asset3d, *asset3d.GetMesh()); 33 | } 34 | 35 | processor.ProcessAsset3DAfterChildren(asset3d); 36 | } 37 | 38 | void Babylon::Transcoder::Asset3DTraverser::Traverse(IAsset3DProcessor& processor, SceneNode& sceneNode) 39 | { 40 | processor.ProcessSceneNodeBeforeChildren(sceneNode); 41 | 42 | for (auto& child : sceneNode.GetChildren()) 43 | { 44 | m_depth++; 45 | Traverse(processor, *child); 46 | m_depth--; 47 | } 48 | 49 | if (sceneNode.HasMesh()) 50 | { 51 | Traverse(processor, sceneNode, *sceneNode.GetMesh()); 52 | } 53 | 54 | processor.ProcessSceneNodeAfterChildren(sceneNode); 55 | } 56 | 57 | void Babylon::Transcoder::Asset3DTraverser::Traverse(IAsset3DProcessor& processor, SceneNode& sceneNode, Mesh& mesh) 58 | { 59 | processor.ProcessMeshBeforeMaterialAndGeometry(sceneNode, mesh); 60 | 61 | processor.ProcessMesh(sceneNode, mesh); 62 | 63 | for (auto& geometry : mesh.GetGeometries()) 64 | { 65 | processor.ProcessGeometry(sceneNode, mesh, geometry); 66 | 67 | const auto& material = geometry.GetMaterial(); 68 | processor.ProcessMaterial(*material); 69 | 70 | for (auto& texture : material->GetTextures()) 71 | { 72 | processor.ProcessTexture(*texture.second); 73 | } 74 | } 75 | 76 | processor.ProcessMeshAfterMaterialAndGeometry(sceneNode, mesh); 77 | } 78 | 79 | size_t Babylon::Transcoder::Asset3DTraverser::GetDepth() const 80 | { 81 | return m_depth; 82 | } -------------------------------------------------------------------------------- /Morphs/Importers/Utils/Asset3D/Source/BoundingBox.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #include "Asset3DPch.h" 7 | 8 | #include 9 | 10 | using namespace Babylon::Transcoder; 11 | 12 | const BoundingBox BoundingBox::Zero(0, 0, 0, 0, 0, 0); 13 | const BoundingBox BoundingBox::Uninitialized(+FLT_MAX, -FLT_MAX, +FLT_MAX, -FLT_MAX, +FLT_MAX, -FLT_MAX); 14 | 15 | BoundingBox::BoundingBox() 16 | : m_isInitialised(false), 17 | m_minima{ {+FLT_MAX, +FLT_MAX, +FLT_MAX} }, 18 | m_maxima{ {-FLT_MAX, -FLT_MAX, -FLT_MAX} } 19 | { 20 | } 21 | 22 | BoundingBox::BoundingBox(const BoundingBox& other) 23 | : m_isInitialised(other.m_isInitialised), 24 | m_minima(other.m_minima), 25 | m_maxima(other.m_maxima) 26 | { 27 | } 28 | 29 | BoundingBox::BoundingBox(std::vector const& positions) 30 | : m_isInitialised(true), 31 | m_minima{ {+FLT_MAX, +FLT_MAX, +FLT_MAX} }, 32 | m_maxima{ {-FLT_MAX, -FLT_MAX, -FLT_MAX} } 33 | { 34 | if (positions.empty()) 35 | { 36 | m_isInitialised = false; 37 | } 38 | else 39 | { 40 | Update(positions); 41 | } 42 | } 43 | 44 | BoundingBox::BoundingBox(std::array center, std::array extents) 45 | : m_isInitialised(true), 46 | m_minima{ {center[0] - extents[0], center[1] - extents[1], center[2] - extents[2]} }, 47 | m_maxima{ {center[0] + extents[0], center[1] + extents[1], center[2] + extents[2]} } 48 | { 49 | Validate(); 50 | } 51 | 52 | BoundingBox::BoundingBox(float minX, float maxX, float minY, float maxY, float minZ, float maxZ) 53 | : m_isInitialised(true), 54 | m_minima{ {minX, minY, minZ} }, 55 | m_maxima{ {maxX, maxY, maxZ} } 56 | { 57 | Validate(); 58 | } 59 | 60 | BoundingBox::~BoundingBox() 61 | { 62 | } 63 | 64 | void BoundingBox::Transform(Babylon::Utils::Math::Matrix transform) 65 | { 66 | if (!m_isInitialised) 67 | { 68 | return; 69 | } 70 | 71 | Vector3 bounds[] = { {m_minima[0], m_minima[1], m_minima[2]}, 72 | {m_maxima[0], m_maxima[1], m_maxima[2]} }; 73 | 74 | m_isInitialised = false; 75 | m_minima = { {+FLT_MAX, +FLT_MAX, +FLT_MAX} }; 76 | m_maxima = { {-FLT_MAX, -FLT_MAX, -FLT_MAX} }; 77 | 78 | for (int i = 0; i < 8; i++) 79 | { 80 | Vector3 position = { bounds[(i & 4) >> 2].x, bounds[(i & 2) >> 1].y, bounds[i & 1].z }; 81 | Update(Babylon::Utils::Math::Vector3::Transform(position, transform)); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/Asset3D/Source/ITraversableBase.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #include "Asset3DPch.h" 7 | 8 | #include 9 | 10 | uint32_t Babylon::Transcoder::ITraversableBase::s_idCount = 0; 11 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(CoreUtils) 2 | add_subdirectory(Framework) 3 | add_subdirectory(CanvasTex) 4 | add_subdirectory(ImagingComponent) 5 | add_subdirectory(Asset3D) 6 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CanvasTex/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # CanvasTex 2 | file(GLOB SOURCES CONFIGURE_DEPENDS 3 | "Include/CanvasTex/*.h" 4 | "Source/*.h" 5 | "Source/Win/*.h" 6 | "Source/Win/*.cpp") 7 | 8 | add_library(CanvasTex ${SOURCES}) 9 | 10 | target_include_directories(CanvasTex PUBLIC "Include") 11 | 12 | target_compile_definitions(CanvasTex 13 | PRIVATE NOMINMAX) 14 | 15 | set_property(TARGET CanvasTex PROPERTY FOLDER Utils) 16 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES}) 17 | 18 | target_link_libraries(CanvasTex 19 | CoreUtils 20 | Framework 21 | ) 22 | 23 | if(WIN32) 24 | target_link_libraries(CanvasTex 25 | DirectXTex 26 | d3d11.lib 27 | dxgi.lib 28 | windowscodecs.lib) 29 | endif() 30 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CanvasTex/Include/CanvasTex/ScratchImage.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace CanvasTex 16 | { 17 | class ScratchImage final 18 | { 19 | public: 20 | class ScratchImageImplementation; 21 | 22 | ScratchImage(); 23 | ~ScratchImage(); 24 | 25 | ScratchImage(const ScratchImage& other) = delete; 26 | ScratchImage& operator=(const ScratchImage& other) = delete; 27 | 28 | ScratchImage(ScratchImage&& other); 29 | ScratchImage& operator=(ScratchImage&& other); 30 | 31 | void InitializeFromImage(const Image& srcImage); 32 | 33 | void Release(); 34 | 35 | ConstTextureMetadata GetMetadata() const; 36 | 37 | ConstImage GetImage(size_t item, size_t mip) const; 38 | 39 | size_t GetImageCount() const; 40 | 41 | const uint8_t* GetPixels() const; 42 | uint8_t* GetPixels(); 43 | 44 | size_t GetPixelsSize() const; 45 | 46 | ScratchImageImplementation& GetImplementation(); 47 | const ScratchImageImplementation& CGetImplementation() const; 48 | 49 | private: 50 | std::shared_ptr m_impl; 51 | }; 52 | } // namespace CanvasTex 53 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CanvasTex/Source/CanvasTexUtils.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | 12 | namespace CanvasTex 13 | { 14 | template 15 | void PrepareAndProcess(const ConstImage& image, TextureFormat textureFormat, const Fn& fn) 16 | { 17 | if (textureFormat == TextureFormat::Unknown) 18 | { 19 | textureFormat = TextureFormat::B8g8r8a8Unorm; 20 | } 21 | 22 | if (IsCompressed(image.GetFormat())) 23 | { 24 | ScratchImage uncompressed; 25 | Decompress(image, textureFormat, uncompressed); 26 | 27 | fn(uncompressed.GetImage(0, 0)); 28 | } 29 | else if (image.GetFormat() != textureFormat) 30 | { 31 | ScratchImage converted; 32 | Convert(image, textureFormat, converted); 33 | 34 | fn(converted.GetImage(0, 0)); 35 | } 36 | else 37 | { 38 | fn(image); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CanvasTex/Source/Win/CanvasTexPch.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #include "CanvasTexPch.h" 8 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CanvasTex/Source/Win/CanvasTexPch.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CanvasTex/Source/Win/DxDevice.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | namespace CanvasTex 12 | { 13 | namespace Internal 14 | { 15 | 16 | // Creates a DirectX Adapter for use of BC7 Compression 17 | // Adapter chosen will support at least DirectX level 10 and Compute Shaders. 18 | // returns false If no suitable adapter is available. 19 | bool CreateDXDevice(ID3D11Device** pDevice); 20 | 21 | } // namespace Internal 22 | } // namespace CanvasTex 23 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CanvasTex/Source/Win/FormatConversion.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #include 12 | 13 | namespace CanvasTex 14 | { 15 | namespace Internal 16 | { 17 | 18 | DXGI_FORMAT TextureFormatToDxgiFormat(TextureFormat format); 19 | 20 | TextureFormat DxgiFormatToTextureFormat(DXGI_FORMAT format); 21 | 22 | } // namespace Internal 23 | } // namespace CanvasTex 24 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CanvasTex/Source/Win/Image.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | namespace CanvasTex 13 | { 14 | class ImageBase::ImageImplementation : public ::DirectX::Image 15 | { 16 | }; 17 | } // namespace CanvasTex 18 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CanvasTex/Source/Win/MedianCutQuantizer.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BabylonJS/BabylonPolymorph/5a12b0514eee3c0d209e12ac6815d76296c3fa7c/Morphs/Importers/Utils/CanvasTex/Source/Win/MedianCutQuantizer.cpp -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CanvasTex/Source/Win/MedianCutQuantizer.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #include 12 | 13 | namespace CanvasTex 14 | { 15 | namespace MedianCutQuantizer 16 | { 17 | void QuantizeImage(const uint8_t* const sourceData, const size_t width, const size_t height, const size_t stride, IWICBitmap* const pDest, const uint32_t nMaxColors); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CanvasTex/Source/Win/ScratchImage.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #include "CanvasTexPch.h" 8 | 9 | #include "ScratchImage.h" 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | #include "Image.h" 17 | #include "TextureMetadata.h" 18 | 19 | namespace CanvasTex 20 | { 21 | ScratchImage::ScratchImage() 22 | : m_impl{ std::make_shared() } 23 | { 24 | } 25 | 26 | ScratchImage::~ScratchImage() = default; 27 | 28 | ScratchImage::ScratchImage(ScratchImage&& other) = default; 29 | 30 | ScratchImage& ScratchImage::operator=(ScratchImage&& other) = default; 31 | 32 | void ScratchImage::InitializeFromImage(const Image& srcImage) 33 | { 34 | Babylon::Utils::ThrowIfFailed(m_impl->InitializeFromImage(srcImage.CGetImplementation())); 35 | } 36 | 37 | void ScratchImage::Release() 38 | { 39 | m_impl->Release(); 40 | } 41 | 42 | ConstTextureMetadata ScratchImage::GetMetadata() const 43 | { 44 | auto metaImplementation = static_cast(&m_impl->GetMetadata()); 45 | return ConstTextureMetadata(std::shared_ptr(m_impl, metaImplementation)); 46 | } 47 | 48 | ConstImage ScratchImage::GetImage(size_t item, size_t mip) const 49 | { 50 | auto imageImplementation = static_cast(m_impl->GetImage(mip, item, 0)); 51 | return ConstImage(std::shared_ptr(m_impl, imageImplementation)); 52 | } 53 | 54 | size_t ScratchImage::GetImageCount() const 55 | { 56 | return m_impl->GetImageCount(); 57 | } 58 | 59 | const uint8_t* ScratchImage::GetPixels() const 60 | { 61 | return m_impl->GetPixels(); 62 | } 63 | 64 | uint8_t* ScratchImage::GetPixels() 65 | { 66 | return m_impl->GetPixels(); 67 | } 68 | 69 | size_t ScratchImage::GetPixelsSize() const 70 | { 71 | return m_impl->GetPixelsSize(); 72 | } 73 | 74 | ScratchImage::ScratchImageImplementation& ScratchImage::GetImplementation() 75 | { 76 | return *m_impl; 77 | } 78 | 79 | const ScratchImage::ScratchImageImplementation& ScratchImage::CGetImplementation() const 80 | { 81 | return *m_impl; 82 | } 83 | 84 | } // namespace CanvasTex 85 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CanvasTex/Source/Win/ScratchImage.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | namespace CanvasTex 13 | { 14 | class ScratchImage::ScratchImageImplementation : public ::DirectX::ScratchImage 15 | { 16 | }; 17 | } // namespace CanvasTex 18 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CanvasTex/Source/Win/TextureMetadata.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #include 12 | 13 | namespace CanvasTex 14 | { 15 | 16 | class TextureMetadataBase::TextureMetadataImplementation : public ::DirectX::TexMetadata 17 | { 18 | }; 19 | 20 | } // namespace CanvasTex 21 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CanvasTex/Source/Win/WindowsCommon.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #include "CanvasTexPch.h" 8 | 9 | #include "WindowsCommon.h" 10 | 11 | #include 12 | 13 | DEFINE_TRACE_AREA(CanvasTex_Internal, Trace::Info); 14 | 15 | //----------------------------------------------------------------------------- 16 | 17 | namespace CanvasTex 18 | { 19 | namespace Internal 20 | { 21 | 22 | //--------------------------------------------------------------------------------------------------------------------- 23 | 24 | HRESULT GetImagingFactory( 25 | IWICImagingFactory** factory) 26 | { 27 | // MULTI_QI has three members: 28 | // - the identifier for a requested interface (pIID) 29 | // - the location to return the interface pointer (pItf) 30 | // - the return value of the call to QueryInterface (hr) 31 | // Initialize to zero then set our requested interface 32 | MULTI_QI mq = { 0 }; 33 | mq.pIID = &IID_IWICImagingFactory; 34 | #ifdef __cplusplus_winrt 35 | HRESULT hr = CoCreateInstanceFromApp(CLSID_WICImagingFactory, nullptr, CLSCTX_INPROC_SERVER, nullptr, 1, &mq); 36 | #else 37 | HRESULT hr = CoCreateInstanceEx(CLSID_WICImagingFactory, nullptr, CLSCTX_INPROC_SERVER, nullptr, 1, &mq); 38 | #endif 39 | 40 | // strangely the standard insists that you must examine the return value as well as the mq.hr value 41 | // presumably, because the function can fail before the mq.hr value is set 42 | if ((mq.hr == S_OK) && (hr == S_OK)) 43 | { 44 | *factory = static_cast(mq.pItf); 45 | } 46 | else 47 | { 48 | *factory = nullptr; 49 | TRACE_ERROR(CanvasTex_Internal, "Failed to create WICImagingFactory COM object"); 50 | } 51 | return mq.hr; 52 | } 53 | 54 | } // namespace Internal 55 | } // namespace CanvasTex 56 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CanvasTex/Source/Win/WindowsCommon.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | namespace CanvasTex 12 | { 13 | namespace Internal 14 | { 15 | HRESULT GetImagingFactory(IWICImagingFactory** factory); 16 | } // namespace Internal 17 | } // namespace CanvasTex 18 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # CoreUtils 2 | file(GLOB SOURCES CONFIGURE_DEPENDS 3 | "Include/CoreUtils/*.h" 4 | "Include/CoreUtils/Math/*.h" 5 | "Include/CoreUtils/Tweening/*.h" 6 | "Include/DirectXMath/*.h" 7 | "Source/*.h" 8 | "Source/*.cpp" 9 | "Source/Tweening/*.cpp" 10 | "Source/Win/*.cpp") 11 | 12 | add_library(CoreUtils ${SOURCES}) 13 | 14 | target_include_directories(CoreUtils PUBLIC "Include") 15 | 16 | target_compile_definitions(CoreUtils 17 | PRIVATE NOMINMAX) 18 | 19 | set_property(TARGET CoreUtils PROPERTY FOLDER Utils) 20 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES}) 21 | 22 | target_link_libraries(CoreUtils 23 | GLTFSDK 24 | RapidJSON 25 | ) 26 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Include/CoreUtils/Align.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | namespace Babylon 16 | { 17 | namespace Utils 18 | { 19 | inline bool IsAligned(const void* const ptr, size_t alignment) 20 | { 21 | // Valid alignment requirements are always a power of two 22 | if (!Math::IsPowerOfTwo(alignment)) 23 | { 24 | throw BabylonInvalidArgException("IsAligned: alignment argument value is not a power of two"); 25 | } 26 | 27 | return !(reinterpret_cast(ptr) & (alignment - 1U)); 28 | } 29 | 30 | template 31 | inline bool IsAligned(const void* const ptr) 32 | { 33 | return IsAligned(ptr, alignof(T)); 34 | } 35 | 36 | /// \brief 37 | /// Align the value up to be a multiple of the specified alignment. 38 | /// The alignment must be a power of two, or zero for no alignment. 39 | inline Babylon_CONSTEXPR size_t AlignUp(size_t value, size_t alignment) 40 | { 41 | // The requested alignment must be a power of two, or zero for no alignment 42 | BabylonAssert((alignment == 0U) || Math::IsPowerOfTwo(alignment)); 43 | 44 | return (alignment ? ((value + alignment - 1U) & ~(alignment - 1U)) : value); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Include/CoreUtils/AnimationNameChecker.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | namespace Babylon 13 | { 14 | namespace Utils 15 | { 16 | // [Office] Animation names need to be non-empty and unique 17 | class AnimationNameChecker 18 | { 19 | public: 20 | AnimationNameChecker() 21 | { 22 | m_disallowedAnimationNames.emplace(""); // Do not allow empty animation name. 23 | } 24 | 25 | std::string GetUniqueName(const std::string& animationName) 26 | { 27 | // Modify the animation name, if it is a name that is not allowed. 28 | int uniqueNameCount = 0; 29 | std::string uniqueName = animationName; 30 | std::string baseName = animationName.empty() ? k_animationNamePrefix : animationName; 31 | while (!m_disallowedAnimationNames.insert(uniqueName).second) 32 | { 33 | uniqueName = baseName + std::to_string(uniqueNameCount); 34 | uniqueNameCount++; 35 | } 36 | return uniqueName; 37 | } 38 | 39 | private: 40 | const std::string k_animationNamePrefix = "animation_"; 41 | std::unordered_set m_disallowedAnimationNames; 42 | }; 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Include/CoreUtils/BabylonConstExpr.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #if !defined(Babylon_CONSTEXPR_H) 10 | #define Babylon_CONSTEXPR_H 11 | 12 | // Older compiler versions don't support constexpr as broadly, so don't use it in those contexts. 13 | // Logic based on similar logic in DirectXMath (XM_CONST, XM_CONSTEXPR). 14 | #if defined(_MSC_VER) && (_MSC_VER < 1910) 15 | #define Babylon_CONST const 16 | #define Babylon_CONSTEXPR 17 | #else 18 | #define Babylon_CONST constexpr 19 | #define Babylon_CONSTEXPR constexpr 20 | #endif 21 | 22 | #endif // !defined(Babylon_CONSTEXPR_H) 23 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Include/CoreUtils/BabylonSDK.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #if !defined(COREUTILS_BABYLON_SDK_H_INCLUDED) 10 | #define COREUTILS_BABYLON_SDK_H_INCLUDED 11 | 12 | #if defined(_USRDLL) && !defined(BABYLON_SDK_API) 13 | # ifdef BABYLON_SDK_EXPORT 14 | # define BABYLON_SDK_API __declspec(dllexport) 15 | # else 16 | # define BABYLON_SDK_API __declspec(dllimport) 17 | # endif // BabylonSDK_EXPORT 18 | #else 19 | # define BABYLON_SDK_API 20 | #endif 21 | 22 | #if defined(_M_IX86) && !defined(BABYLON_SDK_CALL) 23 | # define BABYLON_SDK_CALL __cdecl 24 | #else 25 | # define BABYLON_SDK_CALL 26 | #endif 27 | 28 | /// Deprecated macro for cases where using [[deprecated]] directly doesn't work in old compiler versions. 29 | #if defined(_MSC_VER) && _MSC_VER < 1910 30 | #define BABYLON_DEPRECATED(MESSAGE) __declspec(deprecated(MESSAGE)) 31 | #else 32 | #define BABYLON_DEPRECATED(MESSAGE) [[deprecated(MESSAGE)]] 33 | #endif 34 | 35 | #endif // COREUTILS_BABYLON_SDK_H_INCLUDED 36 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Include/CoreUtils/BabylonSal.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #if _MSC_VER >= 1700 10 | 11 | // Support VS2012 SAL syntax only 12 | #include 13 | 14 | #else 15 | 16 | #ifndef _In_ 17 | #define _In_ 18 | #endif // _In_ 19 | 20 | #ifndef _In_z_ 21 | #define _In_z_ 22 | #endif // _In_z_ 23 | 24 | #ifndef _In_opt_ 25 | #define _In_opt_ 26 | #endif // _In_opt_ 27 | 28 | #ifndef _In_reads_ 29 | #define _In_reads_(x) 30 | #endif // _In_reads_ 31 | 32 | #ifndef _In_reads_bytes_ 33 | #define _In_reads_bytes_(x) 34 | #endif // _In_reads_bytes_ 35 | 36 | #ifndef __in_ecount 37 | #define __in_ecount(x) 38 | #endif // __in_ecount 39 | 40 | #ifndef _Out_ 41 | #define _Out_ 42 | #endif // _Out_ 43 | 44 | #ifndef _Out_opt_ 45 | #define _Out_opt_ 46 | #endif // _Out_opt_ 47 | 48 | #ifndef _Out_writes_ 49 | #define _Out_writes_(x) 50 | #endif // _Out_writes_ 51 | 52 | #ifndef _Out_writes_bytes_ 53 | #define _Out_writes_bytes_(x) 54 | #endif // _Out_writes_bytes_ 55 | 56 | #ifndef __out_ecount 57 | #define __out_ecount(x) 58 | #endif // __out_ecount 59 | 60 | #ifndef _Success_ 61 | #define _Success_(x) 62 | #endif // _Success_ 63 | 64 | #ifndef _Use_decl_annotations_ 65 | #define _Use_decl_annotations_ 66 | #endif // _Use_decl_annotations_ 67 | 68 | #ifndef _Analysis_assume_ 69 | #define _Analysis_assume_(x) 70 | #endif // _Analysis_assume_ 71 | 72 | #ifndef __cpuid 73 | #define __cpuid 74 | #endif // __cpuid 75 | 76 | #ifndef _Printf_format_string_ 77 | #define _Printf_format_string_ 78 | #endif // _Printf_format_string_ 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Include/CoreUtils/CRC64.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | namespace Babylon 12 | { 13 | namespace Utils 14 | { 15 | namespace CRC64 16 | { 17 | enum class Checksum : uint64_t; 18 | 19 | extern const uint64_t k_CRC64Table[256]; 20 | 21 | Checksum HashByte(Checksum crc, uint8_t byte); 22 | 23 | Checksum HashBytes(Checksum crc, const uint8_t* pData, size_t dataSize); 24 | 25 | Checksum Hash2Bytes(Checksum crc, uint16_t bytes); 26 | 27 | Checksum Hash4Bytes(Checksum crc, uint32_t bytes); 28 | }; 29 | } // namespace Utils 30 | } // namespace Babylon 31 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Include/CoreUtils/Cast.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | namespace Babylon 12 | { 13 | namespace Utils 14 | { 15 | // Runtime check that the passed instance is of type TTest 16 | template 17 | bool Babylon_is_type(const TInput& input) 18 | { 19 | static_assert(std::is_base_of::value, "Template parameter TTest must derive from TInput"); 20 | return dynamic_cast(&input) != nullptr; 21 | } 22 | 23 | // Babylon_safe_cast is used where the input is known (by design) to be of the correct type, 24 | // so that only a static_cast<> is required for efficiency. 25 | // 26 | // In debug builds, this a full dynamic_cast is used to assert the precondition. 27 | template 28 | Output* Babylon_safe_cast(Input* input) 29 | { 30 | BabylonAssert(input && Babylon_is_type(*input)); 31 | return static_cast(input); 32 | } 33 | 34 | // Babylon_safe_pointer_cast is used where the input is known (by design) to be of the correct type, 35 | // so that only a static_pointer_cast<> is required for efficiency. 36 | // 37 | // In debug builds, this a full dynamic_cast is used to assert the precondition. 38 | template 39 | std::shared_ptr Babylon_safe_pointer_cast(std::shared_ptr input) 40 | { 41 | BabylonAssert(input && Babylon_is_type(*input)); 42 | return std::static_pointer_cast(input); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Include/CoreUtils/DirectProperty.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #if !defined(_FUNCTIONAL_) 10 | #include 11 | #endif // _FUNCTIONAL_ 12 | 13 | #include "Property.h" 14 | 15 | namespace Babylon 16 | { 17 | namespace Utils 18 | { 19 | /// \brief DirectProperty derives from Property and provides a mechanism for setting and 20 | /// getting value stored inside the class. 21 | /// 22 | /// At the moment this class is not the most exciting in the world. 23 | /// It serves as a wrapper over a custom type T with Set and Get functions. 24 | /// It provides some C# like convenience for getting and setting values with no need of calling set and get, 25 | /// but unlike C# provides NO access control to setters and getters (private, public), cannot be defined 26 | /// declaratively - you must provide setter and getter in the constructor while you instantiate the class. 27 | /// 28 | template 29 | class DirectProperty : public IProperty 30 | { 31 | public: 32 | DirectProperty(const T& val) 33 | : m_propertyValue(val) 34 | { 35 | } 36 | virtual void Set(const T& val) { m_propertyValue = val; } 37 | virtual T Get() const { return m_propertyValue; } 38 | 39 | void operator=(const T& val) { Set(val);} 40 | operator T () const { return Get(); } 41 | 42 | private: 43 | T m_propertyValue; 44 | }; 45 | 46 | template 47 | using PropertyConnectionDirect = std::shared_ptr; 48 | 49 | }// end Utils 50 | }// end Babylon 51 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Include/CoreUtils/Enum.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | namespace Babylon 12 | { 13 | namespace Utils 14 | { 15 | template 16 | constexpr auto underlying_cast(const T elem) 17 | { 18 | static_assert(std::is_enum::value, "underlying_cast only operates on enum types"); 19 | 20 | return static_cast>(elem); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Include/CoreUtils/FileIO.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #if !defined __cplusplus_winrt 10 | 11 | #if !defined(_STRING_) 12 | #include 13 | #endif // _STRING_ 14 | 15 | #if !defined(_VECTOR_) 16 | #include 17 | #endif // _VECTOR_ 18 | 19 | namespace Babylon 20 | { 21 | 22 | namespace Utils 23 | { 24 | 25 | namespace IO 26 | { 27 | 28 | bool FileExists(const std::string &fileName); 29 | bool FileExists(const std::wstring &fileName); 30 | 31 | std::vector GetFilesInDirectory(std::wstring const& path, std::wstring const& filter = L""); 32 | 33 | } // namespace IO 34 | 35 | } // namespace Utils 36 | 37 | } // namespace Babylon 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Include/CoreUtils/Hash.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #if !defined(_FUNCTIONAL_) 12 | #include 13 | #endif // _FUNCTIONAL_ 14 | 15 | namespace Babylon 16 | { 17 | namespace Utils 18 | { 19 | inline uint32_t Hash(const char *str) 20 | { 21 | if (str == nullptr) 22 | { 23 | return 0; 24 | } 25 | 26 | unsigned int hash = 5381; 27 | 28 | while (*str) 29 | { 30 | hash = ((hash << 5) + hash) + *str; 31 | ++str; 32 | } 33 | return hash; 34 | } 35 | 36 | inline void HashCombine(std::size_t& /*seed*/) {} 37 | 38 | template 39 | void HashCombine(std::size_t& seed, const T& t) 40 | { 41 | // This method of combining hashes is from boost::hash_combine - http://www.boost.org/doc/libs/1_62_0/boost/functional/hash/hash.hpp 42 | seed ^= std::hash{}(t) + 0x9e3779b9 + (seed << 6) + (seed >> 2); 43 | } 44 | 45 | template 46 | void HashCombine(std::size_t& seed, const T& t, A&& ...args) 47 | { 48 | HashCombine(seed, t); 49 | HashCombine(seed, std::forward(args)...); 50 | } 51 | 52 | template 53 | std::size_t HashArgs(const T& t, A&& ...args) 54 | { 55 | std::size_t hash = std::hash{}(t); 56 | HashCombine(hash, std::forward(args)...); 57 | return hash; 58 | } 59 | 60 | } // End namespace Utils 61 | } // End namespace 62 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Include/CoreUtils/IndirectProperty.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #if !defined(_FUNCTIONAL_) 10 | #include 11 | #endif // _FUNCTIONAL_ 12 | 13 | #include "Property.h" 14 | 15 | #include 16 | 17 | namespace Babylon 18 | { 19 | namespace Utils 20 | { 21 | /// \brief IndirectProperty derives from Property and provides a mechanism for setting and 22 | /// getting values via setter and getter function pointers. 23 | /// 24 | /// It works well as a proxy for wrapping API into property interface so it can be passed to 25 | /// TweenManager for creating tweens. 26 | template 27 | class IndirectProperty : public IProperty 28 | { 29 | public: 30 | /// A constructor 31 | /// 32 | /// \param setMethod - function pointer for setting value, function pointer for getter is null in this case 33 | IndirectProperty(const std::function& setMethod) : 34 | m_setter(setMethod) 35 | { 36 | } 37 | 38 | /// A constructor 39 | /// 40 | /// \param setMethod - function pointer for setting value 41 | /// \param getMethod - function pointer for getting value 42 | IndirectProperty(const std::function& setMethod, 43 | const std::function& getMethod) : 44 | m_setter(setMethod), 45 | m_getter(getMethod) 46 | { 47 | } 48 | 49 | virtual ~IndirectProperty() = default; 50 | 51 | virtual void Set(const T& val) 52 | { 53 | m_setter(val); 54 | } 55 | 56 | virtual T Get() const 57 | { 58 | if (m_getter) 59 | { 60 | return m_getter(); 61 | } 62 | throw Babylon::Utils::BabylonException("Getter has not been set"); 63 | } 64 | 65 | void operator=(const T& val) { Set(val); } 66 | operator T () const { return Get(); } 67 | 68 | private: 69 | std::function m_setter; 70 | std::function m_getter; 71 | }; 72 | 73 | template 74 | using PropertyConnection = std::shared_ptr<::Babylon::Utils::IProperty>; 75 | 76 | }// end Utils 77 | }// end Babylon 78 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Include/CoreUtils/Memory.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #ifndef _MSC_VER 12 | #define Babylon_MEMORY_MEMCPY_S_IMPL 13 | #endif 14 | 15 | namespace Babylon 16 | { 17 | namespace Utils 18 | { 19 | 20 | void FastMemSet(uint8_t* destination, uint64_t size, uint8_t value); 21 | int32_t FastMemCopy(uint8_t* destination, uint64_t destinationSize, uint8_t const* source, uint64_t sourceSize); 22 | 23 | #ifdef Babylon_MEMORY_MEMCPY_S_IMPL 24 | 25 | int SafeMemCopy(void* const _Destination, size_t const _DestinationSize, void const* const _Source, size_t const _SourceSize); 26 | 27 | #endif 28 | }; 29 | }; 30 | 31 | #ifdef Babylon_MEMORY_MEMCPY_S_IMPL 32 | 33 | // define memcpy_s for non-VS platforms. 34 | #define memcpy_s ::Babylon::Utils::SafeMemCopy 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Include/CoreUtils/Pimpl.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include 9 | 10 | // Note: include this file in the header and PimplImpl.h in the .cpp 11 | 12 | // Usage: 13 | // 14 | // #include 15 | // 16 | // class SomeType 17 | // { 18 | // class Impl; 19 | // Pimpl m_impl; 20 | // }; 21 | 22 | namespace Babylon 23 | { 24 | namespace Utils 25 | { 26 | enum class PimplCreationMode 27 | { 28 | Default = 0, 29 | Lazy 30 | }; 31 | 32 | namespace Detail 33 | { 34 | template 35 | struct Tag {}; 36 | } 37 | 38 | constexpr Detail::Tag PimplLazyTag = {}; 39 | constexpr Detail::Tag PimplDefaultTag = {}; 40 | 41 | template 42 | class Pimpl final 43 | { 44 | public: 45 | template 46 | Pimpl(Detail::Tag tag = PimplDefaultTag); 47 | 48 | template 49 | Pimpl(TArgs&& ...); 50 | Pimpl(Pimpl&& pimpl); 51 | 52 | ~Pimpl(); 53 | 54 | template 55 | void Create(TArgs&& ...); 56 | void Create(Pimpl&& pimpl); 57 | 58 | void Delete(); 59 | 60 | Pimpl& operator=(Pimpl&&); 61 | Pimpl& operator=(const Pimpl&) = delete; 62 | 63 | explicit operator bool() const; 64 | 65 | T* operator->(); 66 | const T* operator->() const; 67 | 68 | T& operator*(); 69 | const T& operator*() const; 70 | 71 | private: 72 | std::unique_ptr m_ptr; 73 | }; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Include/CoreUtils/Pointers.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | // Examples: 12 | // MyClassPtr = std::shared_ptr (suitable for storage and passing as argument to function that needs to extend lifetime) 13 | // SceneCPtr = std::shared_ptr (suitable for storage and passing as const argument to function that needs to extend lifetime) 14 | // SceneWeakPtr = std::weak_ptr (suitable for storage when you don't want to extend lifetime or incur circular references) 15 | // SceneWeakCPtr = std::weak_ptr (suitable for storage and passing as const argument to function when you don't want to extend lifetime) 16 | #define Babylon_SMART_POINTER_(TYPE, CLASS) \ 17 | TYPE CLASS; \ 18 | using CLASS##Ptr = std::shared_ptr; \ 19 | using CLASS##CPtr = std::shared_ptr; \ 20 | using CLASS##WeakPtr = std::weak_ptr; \ 21 | using CLASS##WeakCPtr = std::weak_ptr 22 | 23 | #define Babylon_SMART_POINTER(CLASS) Babylon_SMART_POINTER_(class, CLASS) 24 | 25 | namespace Babylon 26 | { 27 | namespace Utils 28 | { 29 | Babylon_SMART_POINTER(ICancellationToken); 30 | Babylon_SMART_POINTER(IConfigurationManager); 31 | Babylon_SMART_POINTER(RequestManager); 32 | 33 | namespace Tweening 34 | { 35 | Babylon_SMART_POINTER(Tween); 36 | Babylon_SMART_POINTER(TweenManager); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Include/CoreUtils/Property.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #if !defined(_FUNCTIONAL_) 10 | #include 11 | #endif // _FUNCTIONAL_ 12 | 13 | namespace Babylon 14 | { 15 | namespace Utils 16 | { 17 | /// \brief Property class provides a generic interface for getting and setting value of type T 18 | template 19 | class IProperty 20 | { 21 | public: 22 | virtual void Set(const T& val) = 0; 23 | virtual T Get() const = 0; 24 | }; 25 | 26 | }// end Utils 27 | }// end Babylon 28 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Include/CoreUtils/RapidJson.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #if defined(RAPIDJSON_NAMESPACE) 10 | #error Another file has likely already included rapidjson.h before this. This could result in compiling or linking with a different version of rapidjson than we expect. \ 11 | This is known to cause runtime errors if different versions of rapidjson are included in the same namespace. \ 12 | Babylon Canvas code should only include rapidjson using this header. \ 13 | If this is being included from another library then it is important to separate the code in that library from our own use of rapidjson. \ 14 | Please do not include their headers and this header in the same cpp file. 15 | #endif 16 | 17 | #define RAPIDJSON_NAMESPACE Babylon::rapidjson 18 | #define RAPIDJSON_NAMESPACE_BEGIN namespace Babylon { namespace rapidjson { 19 | #define RAPIDJSON_NAMESPACE_END } } 20 | 21 | // rapidjson 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #pragma warning(push) 28 | // Bitwise and with zero. This is due to preprocessor definitions controlling rapidjson behavior that in the default case result in such an operation. 29 | // The logic is still correct, but technically could be optimized away with a little more work, but we don't want to modify rapidjson for this yet. 30 | #pragma warning(disable: 6313) 31 | #include 32 | #pragma warning(pop) 33 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Include/CoreUtils/ScopeWarden.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | /** 7 | * @file 8 | * 9 | * Scope guard implementation by S.T.L. 10 | * 11 | * @requiredheaders exception, memory 12 | */ 13 | 14 | #pragma once 15 | #ifndef PLATFORM_SCOPEWARDEN_H 16 | #define PLATFORM_SCOPEWARDEN_H 17 | 18 | #include 19 | #include 20 | 21 | #include 22 | 23 | /** 24 | * Scope guard implementation. 25 | * 26 | * The scope guard is given a cleanup functor on creation which it will run when 27 | * it is destroyed. Calling Clear will stop the guard from calling the cleanup 28 | * functor on destruction. 29 | */ 30 | template 31 | class 32 | ScopeWarden 33 | { 34 | public: 35 | /** 36 | * Creates a new scope guard. 37 | */ 38 | explicit 39 | ScopeWarden( 40 | F& f /**< The cleanup functor. 41 | * The functor lifetime must be at least as long as the guard. 42 | */ 43 | ) noexcept 44 | : 45 | m_p(std::addressof(f)) 46 | { 47 | // do nothing 48 | } 49 | 50 | /** 51 | * Clear the scope guard, the cleanup functor will not be called anymore. 52 | */ 53 | void 54 | Clear() noexcept 55 | { 56 | m_p = nullptr; 57 | } 58 | 59 | /** 60 | * Runs the cleanup functor unless Clear has been called. 61 | */ 62 | ~ScopeWarden() noexcept 63 | { 64 | if (m_p) 65 | { 66 | #ifndef _XBOX // don't do exception stuff on xbox 67 | try 68 | { 69 | #endif 70 | (*m_p)(); 71 | #ifndef _XBOX // don't do exception stuff on xbox 72 | } 73 | catch (...) 74 | { 75 | BabylonAssertExpr(false, L"The cleanup lambda should not throw."); 76 | std::terminate(); 77 | } 78 | #endif 79 | } 80 | } 81 | 82 | private: 83 | F * m_p; 84 | 85 | explicit ScopeWarden(F&&); 86 | ScopeWarden(const ScopeWarden&); 87 | ScopeWarden& operator=(const ScopeWarden&); 88 | }; 89 | 90 | /** 91 | * Scope guard macro. 92 | * 93 | * Internally creates a ScopeWarden object with the given name and creates a 94 | * cleanup functor from the statements given in the arguments. 95 | */ 96 | #define SCOPE_WARDEN(NAME, ...) \ 97 | auto xx##NAME##xx = [&]() { __VA_ARGS__ }; \ 98 | ScopeWarden NAME(xx##NAME##xx) 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Include/CoreUtils/SharedMutex.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) Microsoft. All rights reserved. 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | namespace Babylon 10 | { 11 | namespace Utils 12 | { 13 | class SharedMutex 14 | { 15 | public: 16 | SharedMutex(); 17 | ~SharedMutex(); 18 | 19 | SharedMutex(const SharedMutex& other) = delete; 20 | const SharedMutex& operator=(const SharedMutex& other) const = delete; 21 | 22 | void lock(); 23 | bool try_lock(); 24 | void unlock(); 25 | 26 | void lock_shared(); 27 | bool try_lock_shared(); 28 | void unlock_shared(); 29 | 30 | private: 31 | class impl; 32 | std::unique_ptr m_pImpl; 33 | }; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Include/CoreUtils/ThreadHelpers.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | namespace Babylon 10 | { 11 | namespace Utils 12 | { 13 | 14 | void SetThreadName(uint32_t threadId, char const* threadName); 15 | } 16 | } 17 | 18 | #ifndef _WIN32 19 | uint32_t GetCurrentThreadId(); 20 | #endif 21 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Include/CoreUtils/Tweening/CurveFactory.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #if !defined(_MEMORY_) 10 | #include 11 | #endif // _MEMORY_ 12 | 13 | #if !defined(COREUTILS_ICURVE_H_INCLUDED) 14 | #include "ICurve.h" 15 | #endif // COREUTILS_ICURVE_H_INCLUDED 16 | 17 | namespace Babylon 18 | { 19 | namespace Utils 20 | { 21 | namespace Tweening 22 | { 23 | enum class CurveType 24 | { 25 | Linear, 26 | QuadraticEaseIn, 27 | QuadraticEaseOut, 28 | QuadraticEaseInOut, 29 | ExponentiaEaseIn, 30 | ExponentiaEaseOut, 31 | ExponentiaEaseInOut, 32 | SineEaseIn, 33 | SineEaseOut, 34 | SineEaseInOut, 35 | BackEaseIn, 36 | BackEaseOut, 37 | BackEaseInOut, 38 | BounceEaseIn, 39 | BounceEaseOut, 40 | BounceEaseInOut, 41 | ElasticEaseIn, 42 | ElasticEaseOut, 43 | ElasticEaseInOut 44 | }; 45 | 46 | class CurveFactory 47 | { 48 | public: 49 | std::unique_ptr GetCurve(CurveType type); 50 | }; 51 | }// end Tweening 52 | } // end Utils 53 | }// end Babylon 54 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Include/CoreUtils/Tweening/ICurve.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #if !defined(COREUTILS_ICURVE_H_INCLUDED) 10 | #define COREUTILS_ICURVE_H_INCLUDED 11 | 12 | namespace Babylon 13 | { 14 | namespace Utils 15 | { 16 | namespace Tweening 17 | { 18 | /// \brief ICurve provides interface for interpolating from A to B using various shapes 19 | class ICurve 20 | { 21 | public: 22 | 23 | /// This is the function that will be implemented by various classes 24 | /// to provide different time interpolation curves. 25 | virtual double Remap(double progress) const = 0; 26 | 27 | virtual ~ICurve() 28 | { 29 | } 30 | }; 31 | 32 | }// end Tweening 33 | } // end Utils 34 | }// end Babylon 35 | 36 | #endif // COREUTILS_ICURVE_H_INCLUDED 37 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Include/CoreUtils/Tweening/ITweenable.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #if !defined(COREUTILS_ICURVE_H_INCLUDED) 10 | #include "ICurve.h" 11 | #endif // COREUTILS_ICURVE_H_INCLUDED 12 | 13 | namespace Babylon 14 | { 15 | namespace Utils 16 | { 17 | namespace Tweening 18 | { 19 | /// \brief ITweenable class provides interface that all tweenable types must implement 20 | class ITweenable 21 | { 22 | public: 23 | virtual ~ITweenable() = default; 24 | 25 | /// Tween interface specifies how custom types should be animated 26 | /// \param value - time progress where 0 is start and 1 is end 27 | /// \param curve - interface that provides mechanism for interpolation 28 | /// \returns True if underlying variable is alive or False if no one hold strong reference to it 29 | virtual bool Tween(double value, const ICurve* curve) = 0; 30 | }; 31 | 32 | }// end Tweening 33 | } // end Utils 34 | }// end Babylon 35 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Include/CoreUtils/Version.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace Babylon 14 | { 15 | namespace Utils 16 | { 17 | // Get the CoreUtils package version string 18 | const char* BABYLON_SDK_CALL GetPackageVersion(); 19 | 20 | } // End namespace Utils 21 | 22 | } // End namespace -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Source/Assert.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #include "CoreUtilsPch.h" 7 | 8 | #include 9 | 10 | BabylonAssertFailHandlerType BabylonAssertFailHandler = nullptr; 11 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Source/ConfigurationValue.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #include "CoreUtilsPch.h" 8 | #include "CoreUtils/ConfigurationValue.h" 9 | 10 | using namespace Babylon::Utils; 11 | 12 | ConfigurationValue::ConfigurationValue(): m_contentType(ConfigurationValue::Object) 13 | { 14 | } 15 | 16 | ConfigurationValue::~ConfigurationValue() 17 | { 18 | } 19 | 20 | ConfigurationValue::ContentType ConfigurationValue::GetType() const 21 | { 22 | return m_contentType; 23 | } 24 | 25 | bool ConfigurationValue::IsObject() const 26 | { 27 | return m_contentType == ConfigurationValue::Object; 28 | } 29 | 30 | bool ConfigurationValue::IsInt() const 31 | { 32 | return m_contentType == ConfigurationValue::Integer; 33 | } 34 | 35 | bool ConfigurationValue::IsDouble() const 36 | { 37 | return m_contentType == ConfigurationValue::Double; 38 | } 39 | 40 | bool ConfigurationValue::IsString() const 41 | { 42 | return m_contentType == ConfigurationValue::String; 43 | } 44 | 45 | bool ConfigurationValue::IsBool() const 46 | { 47 | return m_contentType == ConfigurationValue::Boolean; 48 | } 49 | 50 | bool ConfigurationValue::HasKey(const wchar_t* key) const 51 | { 52 | return m_oContent.find(key) != m_oContent.end(); 53 | } 54 | 55 | std::wstring ConfigurationValue::GetString() const 56 | { 57 | return m_strContent; 58 | } 59 | 60 | int ConfigurationValue::GetInteger() const 61 | { 62 | return m_intContent; 63 | } 64 | 65 | double ConfigurationValue::GetDouble() const 66 | { 67 | return m_dContent; 68 | } 69 | 70 | float ConfigurationValue::GetFloat() const 71 | { 72 | return m_fContent; 73 | } 74 | 75 | bool ConfigurationValue::GetBool() const 76 | { 77 | return m_bContent; 78 | } 79 | 80 | ConfigurationValue& ConfigurationValue::GetContent(std::wstring key) const 81 | { 82 | return m_oContent[key]; 83 | } 84 | 85 | std::vector ConfigurationValue::GetKeys() 86 | { 87 | std::vector keys; 88 | keys.reserve(m_oContent.size()); 89 | for (const auto&kvp : m_oContent) 90 | { 91 | keys.push_back(kvp.first); 92 | } 93 | return keys; 94 | } 95 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Source/CoreUtilsPch.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Source/LexicalCast.cpp: -------------------------------------------------------------------------------- 1 | #include "CoreUtilsPch.h" 2 | #include 3 | 4 | namespace Babylon 5 | { 6 | namespace Utils 7 | { 8 | //-------------------------------------------------------------------------------- 9 | 10 | LexicalCastFailed::LexicalCastFailed(std::string const& reason) : BabylonException(reason, false) { } 11 | 12 | //-------------------------------------------------------------------------------- 13 | 14 | } // namespace Utils 15 | 16 | //-------------------------------------------------------------------------------- 17 | 18 | } // namespace Babylon 19 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Source/PlatformLogger.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | namespace Trace 8 | { 9 | void PrintLogMessage(const char* message); 10 | } // namespace Trace 11 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Source/SmartThrow.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #include "CoreUtilsPch.h" 8 | 9 | #include 10 | 11 | #include 12 | 13 | // We undefine the macro in the cpp so as to avoid expansion in the definition of the 14 | // BabylonException constructors. 15 | #undef BabylonException 16 | 17 | DEFINE_TRACE_AREA(SmartThrow, 0); 18 | 19 | namespace Babylon 20 | { 21 | 22 | namespace Utils 23 | { 24 | 25 | BabylonException::BabylonException(std::string const& message, bool assert) 26 | : std::runtime_error(message) 27 | , m_message(message) 28 | #ifdef _WIN32 29 | , m_win32Error(0) 30 | , m_hr(S_OK) 31 | #endif 32 | { 33 | if (assert) 34 | { 35 | TRACE_WARN(SmartThrow, "Throwing BabylonException with message '%s'", message.c_str()); 36 | BabylonAssert(false); 37 | } 38 | else 39 | { 40 | TRACE_IMPORTANT(SmartThrow, "Throwing BabylonException with message '%s'", message.c_str()); 41 | } 42 | } 43 | 44 | #ifdef _WIN32 45 | 46 | BabylonException::BabylonException(DWORD win32Error, std::string const& message, bool assert) : 47 | std::runtime_error(message.c_str()), 48 | m_message(message), 49 | m_win32Error(win32Error), 50 | m_hr(HRESULT_FROM_WIN32(win32Error)) 51 | { 52 | if (assert) 53 | { 54 | TRACE_WARN(SmartThrow, "Throwing BabylonException with message '%s' and win32 error %u", message.c_str(), m_win32Error); 55 | BabylonAssert(false); 56 | } 57 | else 58 | { 59 | TRACE_IMPORTANT(SmartThrow, "Throwing BabylonException with message '%s' and win32 error %u", message.c_str(), m_win32Error); 60 | } 61 | } 62 | 63 | BabylonException::BabylonException(HRESULT hr, std::string const& message, bool assert) : 64 | std::runtime_error(message.c_str()), 65 | m_message(message), 66 | m_win32Error(0), 67 | m_hr(hr) 68 | { 69 | if (assert) 70 | { 71 | TRACE_WARN(SmartThrow, "Throwing BabylonException with message '%s' and HRESULT error 0x%.8x", message.c_str(), hr); 72 | BabylonAssert(false); 73 | } 74 | else 75 | { 76 | TRACE_IMPORTANT(SmartThrow, "Throwing BabylonException with message '%s' and HRESULT error 0x%.8x", message.c_str(), hr); 77 | } 78 | } 79 | 80 | #endif 81 | 82 | } // namespace Utils 83 | 84 | } // namespace Babylon 85 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Source/Tracked.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #include "CoreUtilsPch.h" 8 | 9 | #include 10 | 11 | DEFINE_TRACE_AREA(Tracked, 0); -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Source/Tweening/CurveFactory.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #include "../CoreUtilsPch.h" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | //-------------------------------------------------------------------------------- 14 | 15 | using namespace Babylon::Utils::Tweening; 16 | 17 | std::unique_ptr Babylon::Utils::Tweening::CurveFactory::GetCurve(CurveType type) 18 | { 19 | switch (type) 20 | { 21 | case CurveType::Linear: return std::make_unique(); 22 | case CurveType::QuadraticEaseIn: return std::make_unique(); 23 | case CurveType::QuadraticEaseOut: return std::make_unique(); 24 | case CurveType::QuadraticEaseInOut: return std::make_unique(); 25 | case CurveType::ExponentiaEaseIn: return std::make_unique(); 26 | case CurveType::ExponentiaEaseOut: return std::make_unique(); 27 | case CurveType::ExponentiaEaseInOut: return std::make_unique(); 28 | case CurveType::SineEaseIn: return std::make_unique(); 29 | case CurveType::SineEaseOut: return std::make_unique(); 30 | case CurveType::SineEaseInOut: return std::make_unique(); 31 | case CurveType::BackEaseIn: return std::make_unique(); 32 | case CurveType::BackEaseOut: return std::make_unique(); 33 | case CurveType::BackEaseInOut: return std::make_unique(); 34 | case CurveType::BounceEaseIn: return std::make_unique(); 35 | case CurveType::BounceEaseOut: return std::make_unique(); 36 | case CurveType::BounceEaseInOut: return std::make_unique(); 37 | case CurveType::ElasticEaseIn: return std::make_unique(); 38 | case CurveType::ElasticEaseOut: return std::make_unique(); 39 | case CurveType::ElasticEaseInOut: return std::make_unique(); 40 | default: 41 | throw BabylonException("Curve type is not supported"); 42 | } 43 | } 44 | 45 | //-------------------------------------------------------------------------------- 46 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Source/Version.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #include "CoreUtilsPch.h" 8 | // TODO: TEMP COMMENT 9 | //#include 10 | #include 11 | 12 | namespace Babylon 13 | { 14 | 15 | namespace Utils 16 | { 17 | // TODO: TEMP COMMENT 18 | /*const char* BabylonSDK_CALL GetPackageVersion() 19 | { 20 | return Babylon_PACKAGE_VERSION; 21 | }*/ 22 | 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Source/Win/CoreUtilsPch.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #include "../CoreUtilsPch.h" 8 | 9 | #include 10 | 11 | DEFINE_TRACE_AREA(BabylonAsync, 0); 12 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Source/Win/PlatformLogger.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #include "../CoreUtilsPch.h" 8 | 9 | #include "../PlatformLogger.h" 10 | 11 | #include 12 | 13 | namespace Trace 14 | { 15 | void PrintLogMessage(const char* message) 16 | { 17 | std::cout << message << std::flush; 18 | } 19 | 20 | } // namespace Trace 21 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/CoreUtils/Source/Win/SharedMutexWin.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2017 Microsoft. 3 | // 4 | 5 | #include "../CoreUtilsPch.h" 6 | #include 7 | 8 | #include 9 | 10 | namespace Babylon 11 | { 12 | namespace Utils 13 | { 14 | 15 | //------------------------------------------------------------------------------------------------------------------------- 16 | 17 | class SharedMutex::impl 18 | { 19 | public: 20 | std::shared_timed_mutex m_mutex; 21 | }; 22 | 23 | //------------------------------------------------------------------------------------------------------------------------- 24 | 25 | SharedMutex::SharedMutex() 26 | : m_pImpl(std::make_unique()) 27 | { 28 | } 29 | 30 | SharedMutex::~SharedMutex() = default; 31 | 32 | void SharedMutex::lock() 33 | { 34 | m_pImpl->m_mutex.lock(); 35 | } 36 | 37 | bool SharedMutex::try_lock() 38 | { 39 | return m_pImpl->m_mutex.try_lock(); 40 | } 41 | 42 | void SharedMutex::unlock() 43 | { 44 | m_pImpl->m_mutex.unlock(); 45 | } 46 | 47 | void SharedMutex::lock_shared() 48 | { 49 | m_pImpl->m_mutex.lock_shared(); 50 | } 51 | 52 | bool SharedMutex::try_lock_shared() 53 | { 54 | return m_pImpl->m_mutex.try_lock_shared(); 55 | } 56 | 57 | void SharedMutex::unlock_shared() 58 | { 59 | m_pImpl->m_mutex.unlock_shared(); 60 | } 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/Framework/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Framework 2 | file(GLOB SOURCES CONFIGURE_DEPENDS 3 | "Include/Framework/*.h" 4 | "Include/Framework/*.hpp" 5 | "Source/*.h" 6 | "Source/*.cpp" 7 | "Source/Win/*.h" 8 | "Source/Win/*.cpp") 9 | 10 | add_library(Framework ${SOURCES}) 11 | 12 | target_include_directories(Framework PUBLIC "Include") 13 | target_include_directories(Framework PUBLIC "Source") 14 | 15 | set_property(TARGET Framework PROPERTY FOLDER Utils) 16 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES}) 17 | 18 | target_link_libraries(Framework 19 | CoreUtils 20 | ) 21 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/Framework/Include/Framework/Endian.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | namespace Babylon 12 | { 13 | namespace Framework 14 | { 15 | namespace Endian 16 | { 17 | inline uint32_t ToNetworkU32(uint32_t v) 18 | { 19 | uint32_t a = v & 0xFF; 20 | uint32_t b = (v >> 8) & 0xFF; 21 | uint32_t c = (v >> 16) & 0xFF; 22 | uint32_t d = (v >> 24) & 0xFF; 23 | return (a << 24) | (b << 16) | (c << 8) | d; 24 | } 25 | 26 | inline uint16_t ToNetworkU16(uint16_t v) 27 | { 28 | uint16_t a = v & 0xFF; 29 | uint16_t b = (v >> 8) & 0xFF; 30 | return (a << 8) | b; 31 | } 32 | 33 | inline uint8_t ToNetworkU8(uint8_t v) 34 | { 35 | return v; 36 | } 37 | 38 | inline uint32_t FromNetworkU32(uint32_t v) 39 | { 40 | return ToNetworkU32(v); 41 | } 42 | 43 | inline uint16_t FromNetworkU16(uint16_t v) 44 | { 45 | return ToNetworkU16(v); 46 | } 47 | 48 | inline uint8_t FromNetworkU8(uint8_t v) 49 | { 50 | return v; 51 | } 52 | 53 | } // namespace Endian 54 | 55 | } // namespace Framework 56 | 57 | } // namespace Babylon 58 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/Framework/Include/Framework/Enums.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | namespace Babylon 12 | { 13 | namespace Framework 14 | { 15 | enum class MaterialLayer : uint8_t 16 | { 17 | kAlbedo = 0, // Could be Diffuse+Alpha or BaseColor+Alpha depending on the value of m_BabylonRenderingMode 18 | kEmissive = 1, 19 | kWorkflow = 2, // Could be Specular+Glossiness or Metallic+Roughness depending on the value of m_BabylonRenderingMode 20 | kNormal = 3, 21 | kDepth = 4, 22 | kOcclusion = 5, 23 | kDetail = 6, 24 | kNumLayers 25 | }; 26 | 27 | // Material Layers to which a texture could be associated 28 | enum class TextureMaterialLayer : uint8_t 29 | { 30 | kDiffuse = 0, 31 | kEmissive = 1, 32 | kSpecularGlossiness = 2, 33 | kNormal = 3, 34 | kDepth = 4, 35 | kOcclusion = 5, 36 | kDetail = 6, 37 | kBaseColor = 7, 38 | kMetallicRoughness = 8, 39 | kNumLayers 40 | }; 41 | 42 | enum class FilterMode : uint8_t 43 | { 44 | kPoint = 1, 45 | kBilinear = 2, 46 | kTrilinear = 3, 47 | kMinPoint_MagPoint_MipPoint = kPoint, 48 | kMinPoint_MagPoint_MipLinear = 4, 49 | kMinPoint_MagLinear_MipPoint = 5, 50 | kMinPoint_MagLinear_MipLinear = 6, 51 | kMinLinear_MagPoint_MipPoint = 7, 52 | kMinLinear_MagPoint_MipLinear = 8, 53 | kMinLinear_MagLinear_MipPoint = kBilinear, 54 | kMinLinear_MagLinear_MipLinear = kTrilinear, 55 | }; 56 | 57 | enum class AddressMode : uint8_t 58 | { 59 | kClamp = 1, 60 | kWrap = 2, 61 | kMirroredWrap = 3 62 | }; 63 | } 64 | } -------------------------------------------------------------------------------- /Morphs/Importers/Utils/Framework/Include/Framework/ManifestParser.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | namespace Babylon 12 | { 13 | namespace Framework 14 | { 15 | class ManifestParser final 16 | { 17 | public: 18 | struct FrameContent 19 | { 20 | Framework::EFrameQuality LOD; 21 | Framework::EFrameCompression Compression; 22 | std::wstring StreamGUID; 23 | uint64_t Size; 24 | }; 25 | 26 | struct Manifest : public std::map> 27 | { 28 | std::wstring Id; 29 | std::wstring PackageVersion; 30 | }; 31 | 32 | public: 33 | ManifestParser( std::wstring const& jsonString ); 34 | Manifest const& Get() const { return m_manifest; } 35 | 36 | private: 37 | Manifest m_manifest; 38 | }; 39 | 40 | } // namespace Framework 41 | } // namespace Babylon 42 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/Framework/Include/Framework/Memory.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | #ifndef _WIN32 13 | inline void* _aligned_malloc(size_t size, size_t alignment) 14 | { 15 | void* ptr; 16 | posix_memalign(&ptr, alignment, size); 17 | return ptr; 18 | } 19 | 20 | inline void _aligned_free(void* ptr) 21 | { 22 | free(ptr); 23 | } 24 | #endif // !_WIN32 25 | 26 | namespace Babylon 27 | { 28 | namespace Framework 29 | { 30 | 31 | template 32 | T* new_aligned(const uint32_t alignment) 33 | { 34 | return reinterpret_cast(_aligned_malloc(sizeof(T), alignment)); 35 | } 36 | 37 | template 38 | T* new_aligned(const uint32_t size, const uint32_t alignment) 39 | { 40 | return reinterpret_cast(_aligned_malloc(size, alignment)); 41 | } 42 | 43 | template 44 | void delete_aligned(T*& allocation) 45 | { 46 | _aligned_free(allocation); 47 | allocation = nullptr; 48 | } 49 | 50 | } // namespace Framework 51 | 52 | } // namespace Babylon 53 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/Framework/Include/Framework/MetadataDefinition.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | namespace Babylon 12 | { 13 | namespace Framework 14 | { 15 | 16 | /** 17 | * Represents the Metadata associated with a model. 18 | * Contains name <-> ID mapping 19 | */ 20 | struct MetadataDefinition 21 | { 22 | enum EVersion 23 | { 24 | kVersion0 = 0x10001000 25 | }; 26 | 27 | uint32_t Version; 28 | uint32_t ID; 29 | 30 | uint16_t NameNumBytes; 31 | uint16_t OffsetName; 32 | 33 | protected: 34 | inline const char* Base() const 35 | { 36 | return reinterpret_cast(this); 37 | } 38 | }; 39 | 40 | ////////////////////////////////////////////////////////////////////////// 41 | 42 | #if (__BYTE_ORDER == __LITTLE_ENDIAN) 43 | 44 | struct MetadataDefinitionBigEndian : MetadataDefinition 45 | { 46 | // Helper methods 47 | inline bool IsValid() const{ return Endian::FromNetworkU32(Version) == kVersion0; } 48 | inline uint32_t GetID() const{return Endian::FromNetworkU32(ID);} 49 | inline uint32_t GetNameLengthInBytes() const{ return Endian::FromNetworkU16(NameNumBytes); } 50 | inline uint16_t* GetName() const { return (uint16_t*)(Base() + Endian::FromNetworkU16(OffsetName)); } 51 | }; 52 | 53 | 54 | struct MetadataDefinitionLittleEndian : MetadataDefinition 55 | { 56 | // Helper methods 57 | inline bool IsValid() const{ return Version == kVersion0; } 58 | inline uint32_t GetID() const{ return ID; } 59 | inline uint32_t GetNameLengthInBytes() const{ return NameNumBytes; } 60 | inline uint16_t* GetName() const { return (uint16_t*)(Base() + OffsetName); } 61 | }; 62 | 63 | 64 | #else 65 | #endif 66 | 67 | } // End namespace Framework 68 | 69 | } // End namespace Babylon 70 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/Framework/Include/Framework/MetadataWriter.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | namespace Babylon 18 | { 19 | namespace Framework 20 | { 21 | /** 22 | * Use the IMetadataWriter to help you serialize out metadata about an object 23 | */ 24 | class BABYLON_SDK_API IMetadataWriter 25 | { 26 | 27 | public: 28 | virtual ~IMetadataWriter() {} 29 | 30 | virtual void BeginFrame( 31 | std::shared_ptr const& outputBuffer, 32 | uint32_t numItems, 33 | EByteOrder byteOrder) = 0; 34 | 35 | virtual Frame* EndFrame() = 0; 36 | 37 | virtual void BeginMetadata(uint32_t id, const char* name) = 0; 38 | virtual void EndMetadata() = 0; 39 | 40 | virtual uint32_t GetVersion() const = 0; 41 | }; 42 | 43 | BABYLON_SDK_API IMetadataWriter* MetadataWriterCreate(); 44 | BABYLON_SDK_API void MetadataWriterDestroy(IMetadataWriter*& pWriter); 45 | 46 | } // End namespace Cool 47 | 48 | } // End namespace Babylon 49 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/Framework/Include/Framework/Pointers.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | Babylon_SMART_POINTER_(struct, IPluginFactory); 12 | Babylon_SMART_POINTER(PluginFactoryBase); 13 | 14 | namespace Babylon 15 | { 16 | namespace Framework 17 | { 18 | Babylon_SMART_POINTER(AnimationMaker); 19 | Babylon_SMART_POINTER(DataMaker); 20 | Babylon_SMART_POINTER(ICancellationToken); 21 | Babylon_SMART_POINTER(ITextureWriter); 22 | Babylon_SMART_POINTER(LightMaker); 23 | Babylon_SMART_POINTER(MaterialMaker); 24 | Babylon_SMART_POINTER(MeshMaker); 25 | Babylon_SMART_POINTER(SkeletonMaker); 26 | Babylon_SMART_POINTER(TextureMaker); 27 | } 28 | 29 | namespace Utils 30 | { 31 | Babylon_SMART_POINTER_(struct, DefaultTimeProvider); 32 | Babylon_SMART_POINTER(ETWTraceProvider); 33 | Babylon_SMART_POINTER_(struct, IMemoryStatsProvider); 34 | Babylon_SMART_POINTER_(struct, ITimeProvider); 35 | Babylon_SMART_POINTER_(struct, ITraceProvider); 36 | Babylon_SMART_POINTER(PerformanceLogger); 37 | Babylon_SMART_POINTER(ITelemetryTraceLogger); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/Framework/Include/Framework/SceneWriter.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | namespace Babylon 19 | { 20 | namespace Framework 21 | { 22 | /** 23 | * Use the ISceneWriter to help you serialize out scene data (e.g. cameras and lights) 24 | * into the common object format. 25 | */ 26 | class BABYLON_SDK_API ISceneWriter 27 | { 28 | 29 | public: 30 | virtual ~ISceneWriter() {} 31 | 32 | virtual void BeginFrame( 33 | const std::shared_ptr& outputBuffer, 34 | int itemCount, 35 | EByteOrder byteOrder) = 0; 36 | 37 | virtual Frame* EndFrame() = 0; 38 | 39 | virtual void AddScene(const SceneDefinition& scene) = 0; 40 | virtual void AddLight(const LightDefinition& light) = 0; 41 | virtual void AddCamera(const CameraDefinition& camera) = 0; 42 | 43 | virtual uint32_t GetVersion() const = 0; 44 | }; 45 | 46 | BABYLON_SDK_API ISceneWriter* SceneWriterCreate(); 47 | BABYLON_SDK_API void SceneWriterDestroy(ISceneWriter*& pWriter); 48 | 49 | 50 | } // End namespace Cool 51 | 52 | } // End namespace Babylon 53 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/Framework/Include/Framework/TelemetryTraceLoggerAliases.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace Babylon 14 | { 15 | namespace Utils 16 | { 17 | class ITelemetryTraceLogger; 18 | using TelemetryTraceLoggerClientCallback = std::function; 19 | using TelemetryTraceLoggerFactoryFunctionType = std::function BABYLON_SDK_CALL()>; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/Framework/Include/Framework/TelemetryTraceLoggerFactory.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #include 12 | 13 | namespace Babylon 14 | { 15 | namespace Utils 16 | { 17 | // Forward declare 18 | class ITelemetryTraceLogger; 19 | 20 | // Use this to get a TelemetryTraceLogger 21 | std::shared_ptr BABYLON_SDK_CALL CreateTelemetryTraceLogger(); 22 | } 23 | } -------------------------------------------------------------------------------- /Morphs/Importers/Utils/Framework/Include/Framework/Types.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | namespace Babylon 12 | { 13 | namespace Framework 14 | { 15 | 16 | typedef uint32_t RGBA; 17 | typedef uint16_t ShortIndex; 18 | typedef uint32_t LongIndex; 19 | 20 | } // End namespace Framework 21 | 22 | } // End namespace Babylon 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/Framework/Source/FrameworkPch.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #include "FrameworkPch.h" 8 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/Framework/Source/FrameworkPch.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #define WIN32_LEAN_AND_MEAN 10 | #ifndef NOMINMAX 11 | #define NOMINMAX 12 | #endif 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | #ifdef _WIN32 45 | # include 46 | # include 47 | #endif 48 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/Framework/Source/ITelemetryTraceLogger.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #include "FrameworkPch.h" 8 | 9 | #include 10 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/Framework/Source/ManifestParser.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #include "FrameworkPch.h" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | typedef Babylon::rapidjson::GenericDocument> WDocument; 14 | typedef Babylon::rapidjson::GenericValue> WValue; 15 | 16 | namespace Babylon 17 | { 18 | namespace Framework 19 | { 20 | 21 | ManifestParser::ManifestParser(std::wstring const& jsonString) 22 | { 23 | WDocument root; 24 | root.Parse(jsonString.c_str()); 25 | 26 | m_manifest.Id = root[L"Id"].GetString(); 27 | m_manifest.PackageVersion = root[L"PackageVersion"].GetString(); 28 | 29 | for (const auto& member : root[L"Resource"].GetObject()) 30 | { 31 | for (const auto& frameData : member.value.GetArray()) 32 | { 33 | FrameContent content; 34 | content.LOD = (Framework::EFrameQuality)frameData[L"LOD"].GetInt(); 35 | content.Compression = (Framework::EFrameCompression)frameData[L"Compression"].GetInt(); 36 | content.StreamGUID = frameData[L"StreamGUID"].GetString(); 37 | if (frameData.HasMember(L"Size")) 38 | { 39 | content.Size = frameData[L"Size"].GetUint64(); 40 | } 41 | 42 | Framework::EFrameType frameType = Framework::kFrameUnknown; 43 | std::wstring frameTypeStr = member.name.GetString(); 44 | 45 | if (frameTypeStr == L"Geometry") frameType = Framework::kFrameGeom; 46 | else if (frameTypeStr == L"Material") frameType = Framework::kFrameMaterial; 47 | else if (frameTypeStr == L"Metadata") frameType = Framework::kFrameMetadata; 48 | else if (frameTypeStr == L"Scene") frameType = Framework::kFrameScene; 49 | else if (frameTypeStr == L"Texture") frameType = Framework::kFrameTexture; 50 | else if (frameTypeStr == L"Animation") frameType = Framework::kFrameAnim; 51 | 52 | m_manifest[frameType].push_back(content); 53 | } 54 | } 55 | } 56 | 57 | } // namespace Engine 58 | } // namespace Babylon 59 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/Framework/Source/Win/TelemetryTraceLoggerFactoryWin.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #include "FrameworkPch.h" 8 | 9 | #include 10 | #include 11 | 12 | #include "TelemetryTraceLoggerWin.h" 13 | 14 | namespace Babylon 15 | { 16 | namespace Utils 17 | { 18 | std::shared_ptr BABYLON_SDK_CALL CreateTelemetryTraceLogger() 19 | { 20 | return std::make_shared(); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /Morphs/Importers/Utils/ImagingComponent/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ImagingComponent 2 | file(GLOB SOURCES CONFIGURE_DEPENDS 3 | "Include/ImagingComponent/*.h" 4 | "Source/*.h" 5 | "Source/*.cpp" 6 | "Source/Win/*.h" 7 | "Source/Win/*.cpp") 8 | 9 | add_library(ImagingComponent ${SOURCES}) 10 | 11 | target_include_directories(ImagingComponent PUBLIC "Include") 12 | 13 | set_property(TARGET ImagingComponent PROPERTY FOLDER Utils) 14 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES}) 15 | 16 | target_link_libraries(ImagingComponent 17 | CoreUtils 18 | Framework 19 | CanvasTex 20 | ) 21 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/ImagingComponent/Include/ImagingComponent/Detection.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #include 12 | 13 | namespace Babylon 14 | { 15 | namespace ImagingV1 16 | { 17 | namespace ImagingComponent 18 | { 19 | 20 | [[deprecated("The ImagingV1 API is deprecated. Please switch to V2.")]] 21 | Framework::ImageReader DetectImageReaderFromHeader( 22 | uint8_t* data, 23 | uint32_t sizeInBytes 24 | ); 25 | 26 | [[deprecated("The ImagingV1 API is deprecated. Please switch to V2.")]] 27 | bool TryGetImageWidthHeight( 28 | void* data, 29 | uint32_t size, 30 | uint32_t& width, 31 | uint32_t& height 32 | ); 33 | 34 | } // namespace ImaginineComponent 35 | } // namespace ImagingV1 36 | } // namespace Babylon 37 | 38 | //--------------------------------------------------------------------------------------------------------------------- 39 | 40 | namespace Babylon 41 | { 42 | namespace ImagingV2 43 | { 44 | namespace ImagingComponent 45 | { 46 | 47 | Framework::ImageReader DetectImageReader( 48 | uint8_t* data, 49 | uint32_t sizeInBytes 50 | ); 51 | 52 | bool TryGetImageWidthHeight( 53 | void* data, 54 | uint32_t size, 55 | uint32_t& width, 56 | uint32_t& height 57 | ); 58 | 59 | } // namespace ImaginineComponent 60 | } // namespace ImagingV2 61 | } // namespace Babylon 62 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/ImagingComponent/Include/ImagingComponent/ImagingComponent.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include "Detection.h" 10 | #include "Encoding.h" 11 | #include "Processing.h" 12 | #include "SpriteSheet.h" 13 | #ifdef _WIN32 14 | #include "Gif.h" 15 | #endif // _WIN32 16 | 17 | namespace Babylon 18 | { 19 | 20 | namespace Imaging = ImagingV2; 21 | 22 | } // namespace Babylon 23 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/ImagingComponent/Include/ImagingComponent/SpriteSheet.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | namespace Babylon 13 | { 14 | namespace ImagingV1 15 | { 16 | namespace ImagingComponent 17 | { 18 | 19 | [[deprecated("The ImagingV1 API is deprecated. Please switch to V2.")]] 20 | std::vector CreateSpriteSheet( 21 | std::vector const& allFramesData, 22 | uint32_t frameHeight, 23 | uint32_t frameWidth 24 | ); 25 | 26 | [[deprecated("The ImagingV1 API is deprecated. Please switch to V2.")]] 27 | void SaveAsSpriteSheet( 28 | std::vector const& allFramesData, 29 | uint32_t frameHeight, 30 | uint32_t frameWidth, 31 | const std::wstring& fileName 32 | ); 33 | 34 | } // namespace ImaginineComponent 35 | } // namespace ImagingV1 36 | } // namespace Babylon 37 | 38 | //--------------------------------------------------------------------------------------------------------------------- 39 | 40 | namespace Babylon 41 | { 42 | namespace ImagingV2 43 | { 44 | namespace ImagingComponent 45 | { 46 | 47 | std::vector CreateSpriteSheet( 48 | std::vector const& allFramesData, 49 | uint32_t frameHeight, 50 | uint32_t frameWidth 51 | ); 52 | 53 | void SaveAsSpriteSheet( 54 | std::vector const& allFramesData, 55 | uint32_t frameHeight, 56 | uint32_t frameWidth, 57 | const std::wstring& fileName 58 | ); 59 | 60 | } // namespace ImaginineComponent 61 | } // namespace ImagingV2 62 | } // namespace Babylon 63 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/ImagingComponent/Source/Common.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #include "Common.h" 8 | 9 | #include 10 | 11 | #include 12 | 13 | //--------------------------------------------------------------------------------------------------------------------- 14 | 15 | namespace Babylon 16 | { 17 | namespace ImagingV2 18 | { 19 | namespace ImagingComponent 20 | { 21 | namespace Internal 22 | { 23 | 24 | //--------------------------------------------------------------------------------------------------------------------- 25 | 26 | void ReadFromMemoryFile( 27 | void* data, 28 | uint32_t size, 29 | CanvasTex::Image& img, 30 | CanvasTex::ScratchImage& result) 31 | { 32 | Framework::ImageReader reader = DetectImageReader((uint8_t*)data, size); 33 | 34 | CanvasTex::TextureMetadata metadata; 35 | auto loadResult = LoadFromMemory(data, size, reader, &metadata, result); 36 | 37 | if (loadResult != CanvasTex::LoadResult::LoadSuccessful) 38 | { 39 | throw Babylon::Utils::BabylonException("Failed to load image from memory."); 40 | } 41 | 42 | img = result.GetImage(0, 0); 43 | } 44 | 45 | } // namespace Internal 46 | } // namespace ImagingComponent 47 | } // namespace ImagingV2 48 | } // namespace Babylon 49 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/ImagingComponent/Source/Common.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #include 12 | 13 | namespace Babylon 14 | { 15 | namespace ImagingV2 16 | { 17 | namespace ImagingComponent 18 | { 19 | namespace Internal 20 | { 21 | 22 | void ReadFromMemoryFile( 23 | void* data, 24 | uint32_t size, 25 | CanvasTex::Image& img, 26 | CanvasTex::ScratchImage& result 27 | ); 28 | 29 | } // namespace Internal 30 | } // namespace ImagingComponent 31 | } // namespace ImagingV2 32 | } // namespace Babylon 33 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/ImagingComponent/Source/Win/WindowsCommon.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #include "WindowsCommon.h" 8 | 9 | #include 10 | 11 | #include 12 | 13 | DEFINE_TRACE_AREA(ImagingComponent_Common, Trace::Info); 14 | 15 | //----------------------------------------------------------------------------- 16 | 17 | namespace Babylon 18 | { 19 | namespace ImagingV2 20 | { 21 | namespace ImagingComponent 22 | { 23 | namespace Internal 24 | { 25 | 26 | //--------------------------------------------------------------------------------------------------------------------- 27 | 28 | HRESULT GetImagingFactory( 29 | IWICImagingFactory** factory) 30 | { 31 | // MULTI_QI has three members: 32 | // - the identifier for a requested interface (pIID) 33 | // - the location to return the interface pointer (pItf) 34 | // - the return value of the call to QueryInterface (hr) 35 | // Initialize to zero then set our requested interface 36 | MULTI_QI mq = { 0 }; 37 | mq.pIID = &IID_IWICImagingFactory; 38 | #ifdef __cplusplus_winrt 39 | HRESULT hr = CoCreateInstanceFromApp(CLSID_WICImagingFactory, nullptr, CLSCTX_INPROC_SERVER, nullptr, 1, &mq); 40 | #else 41 | HRESULT hr = CoCreateInstanceEx(CLSID_WICImagingFactory, nullptr, CLSCTX_INPROC_SERVER, nullptr, 1, &mq); 42 | #endif 43 | 44 | // strangely the standard insists that you must examine the return value as well as the mq.hr value 45 | // presumably, because the function can fail before the mq.hr value is set 46 | if ((mq.hr == S_OK) && (hr == S_OK)) 47 | { 48 | *factory = static_cast(mq.pItf); 49 | } 50 | else 51 | { 52 | *factory = nullptr; 53 | TRACE_ERROR(ImagingComponent_Common, "Failed to create WICImagingFactory COM object"); 54 | } 55 | return mq.hr; 56 | } 57 | 58 | } // namespace Internal 59 | } // namespace ImagingComponent 60 | } // namespace Imaging 61 | } // namespace Babylon 62 | -------------------------------------------------------------------------------- /Morphs/Importers/Utils/ImagingComponent/Source/Win/WindowsCommon.h: -------------------------------------------------------------------------------- 1 | /******************************************************** 2 | * * 3 | * Copyright (C) Microsoft. All rights reserved. * 4 | * * 5 | ********************************************************/ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | namespace Babylon 12 | { 13 | namespace ImagingV2 14 | { 15 | namespace ImagingComponent 16 | { 17 | namespace Internal 18 | { 19 | 20 | HRESULT GetImagingFactory(IWICImagingFactory** factory); 21 | 22 | } // namespace Internal 23 | } // namespace ImagingComponent 24 | } // namespace Imaging 25 | } // namespace Babylon 26 | --------------------------------------------------------------------------------