├── .gitignore ├── GLBGLTFConverter ├── GLBGLTFConverter.cpp ├── GLBGLTFConverter.vcxproj ├── GLBGLTFConverter.vcxproj.filters ├── packages.config ├── stdafx.cpp ├── stdafx.h └── targetver.h ├── LICENSE ├── ModelViewer ├── App.xaml ├── App.xaml.cpp ├── App.xaml.h ├── Assets │ ├── LockScreenLogo.scale-200.png │ ├── Shaders │ │ ├── pbrpixel.hlsl │ │ └── pbrvertex.hlsl │ ├── SplashScreen.scale-200.png │ ├── Square150x150Logo.scale-200.png │ ├── Square44x44Logo.scale-200.png │ ├── Square44x44Logo.targetsize-24_altform-unplated.png │ ├── StoreLogo.png │ ├── Wide310x150Logo.scale-200.png │ └── textures │ │ ├── brdfLUT.png │ │ └── papermill │ │ ├── diffuse │ │ ├── diffuse_back_0.jpg │ │ ├── diffuse_bottom_0.jpg │ │ ├── diffuse_front_0.jpg │ │ ├── diffuse_left_0.jpg │ │ ├── diffuse_right_0.jpg │ │ └── diffuse_top_0.jpg │ │ ├── environment │ │ ├── environment_back_0.jpg │ │ ├── environment_bottom_0.jpg │ │ ├── environment_front_0.jpg │ │ ├── environment_left_0.jpg │ │ ├── environment_right_0.jpg │ │ └── environment_top_0.jpg │ │ └── specular │ │ ├── specular_back_0.jpg │ │ ├── specular_back_1.jpg │ │ ├── specular_back_2.jpg │ │ ├── specular_back_3.jpg │ │ ├── specular_back_4.jpg │ │ ├── specular_back_5.jpg │ │ ├── specular_back_6.jpg │ │ ├── specular_back_7.jpg │ │ ├── specular_back_8.jpg │ │ ├── specular_back_9.jpg │ │ ├── specular_bottom_0.jpg │ │ ├── specular_bottom_1.jpg │ │ ├── specular_bottom_2.jpg │ │ ├── specular_bottom_3.jpg │ │ ├── specular_bottom_4.jpg │ │ ├── specular_bottom_5.jpg │ │ ├── specular_bottom_6.jpg │ │ ├── specular_bottom_7.jpg │ │ ├── specular_bottom_8.jpg │ │ ├── specular_bottom_9.jpg │ │ ├── specular_front_0.jpg │ │ ├── specular_front_1.jpg │ │ ├── specular_front_2.jpg │ │ ├── specular_front_3.jpg │ │ ├── specular_front_4.jpg │ │ ├── specular_front_5.jpg │ │ ├── specular_front_6.jpg │ │ ├── specular_front_7.jpg │ │ ├── specular_front_8.jpg │ │ ├── specular_front_9.jpg │ │ ├── specular_left_0.jpg │ │ ├── specular_left_1.jpg │ │ ├── specular_left_2.jpg │ │ ├── specular_left_3.jpg │ │ ├── specular_left_4.jpg │ │ ├── specular_left_5.jpg │ │ ├── specular_left_6.jpg │ │ ├── specular_left_7.jpg │ │ ├── specular_left_8.jpg │ │ ├── specular_left_9.jpg │ │ ├── specular_right_0.jpg │ │ ├── specular_right_1.jpg │ │ ├── specular_right_2.jpg │ │ ├── specular_right_3.jpg │ │ ├── specular_right_4.jpg │ │ ├── specular_right_5.jpg │ │ ├── specular_right_6.jpg │ │ ├── specular_right_7.jpg │ │ ├── specular_right_8.jpg │ │ ├── specular_right_9.jpg │ │ ├── specular_top_0.jpg │ │ ├── specular_top_1.jpg │ │ ├── specular_top_2.jpg │ │ ├── specular_top_3.jpg │ │ ├── specular_top_4.jpg │ │ ├── specular_top_5.jpg │ │ ├── specular_top_6.jpg │ │ ├── specular_top_7.jpg │ │ ├── specular_top_8.jpg │ │ └── specular_top_9.jpg ├── Axis.cpp ├── Axis.h ├── BooleanToVisibilityConverter.cpp ├── BooleanToVisibilityConverter.h ├── BoundingBox.cpp ├── BoundingBox.h ├── BufferCache.cpp ├── BufferCache.h ├── BufferManager.cpp ├── BufferManager.h ├── ClassDiagram.cd ├── Common │ ├── BindableBase.cpp │ ├── BindableBase.h │ ├── DeviceResources.cpp │ ├── DeviceResources.h │ ├── DirectXHelper.h │ ├── StepTimer.h │ ├── ViewModelBase.cpp │ └── ViewModelBase.h ├── Container.cpp ├── Container.h ├── Content │ ├── Sample3DSceneRenderer.cpp │ ├── Sample3DSceneRenderer.h │ ├── SampleFpsTextRenderer.cpp │ ├── SampleFpsTextRenderer.h │ ├── ShaderStructures.h │ ├── SimplePixelShader.hlsl │ └── SimpleVertexShader.hlsl ├── DXGrid.cpp ├── DXGrid.h ├── DXUtils.cpp ├── DXUtils.h ├── DecimalPlacesConverter.cpp ├── DecimalPlacesConverter.h ├── DelegateCommand.cpp ├── DelegateCommand.h ├── DirectXPage.xaml ├── DirectXPage.xaml.cpp ├── DirectXPage.xaml.h ├── DirectXPageViewModelData.cpp ├── DirectXPageViewModelData.h ├── EventShim.h ├── FileSystemData.h ├── GlyphConverter.cpp ├── GlyphConverter.h ├── ImgUtils.cpp ├── ImgUtils.h ├── ModelBufferManager.cpp ├── ModelBufferManager.h ├── ModelFactory.cpp ├── ModelFactory.h ├── ModelViewer.vcxproj ├── ModelViewer.vcxproj.filters ├── ModelViewerMain.cpp ├── ModelViewerMain.h ├── NodeMaterial.cpp ├── NodeMaterial.h ├── Package.appxmanifest ├── RenderTexture.cpp ├── RenderTexture.h ├── RootPage.xaml ├── RootPage.xaml.cpp ├── RootPage.xaml.h ├── Scene │ ├── CameraNode.cpp │ ├── CameraNode.h │ ├── GraphContainerNode.cpp │ ├── GraphContainerNode.h │ ├── GraphNode.cpp │ ├── GraphNode.h │ ├── LightNode.cpp │ ├── LightNode.h │ ├── MeshNode.cpp │ ├── MeshNode.h │ ├── RootNode.cpp │ ├── RootNode.h │ ├── SceneContext.cpp │ └── SceneContext.h ├── SceneManager.cpp ├── SceneManager.h ├── ShaderCache.cpp ├── ShaderCache.h ├── Singleton.h ├── Subject.h ├── Utility.cpp ├── Utility.h ├── ViewModels │ ├── DirectXPageViewModel.cpp │ ├── DirectXPageViewModel.h │ ├── RootPageViewModel.cpp │ ├── RootPageViewModel.h │ ├── TransformViewModel.cpp │ └── TransformViewModel.h ├── pch.cpp ├── pch.h ├── sub_token.cpp └── sub_token.h ├── README.md ├── SECURITY.md ├── SharedGLTFParser ├── GLBGLTFConverter.cpp ├── GLBGLTFConverter.h ├── SharedGLTFParser.vcxitems ├── SharedGLTFParser.vcxitems.filters ├── gltfparser.cpp ├── gltfparser.h ├── stdafx.h └── targetver.h ├── WinRTGLTFParser ├── GLTF_Parser.cpp ├── GLTF_Parser.h ├── WinRTGLTFParser.vcxproj ├── WinRTGLTFParser.vcxproj.filters ├── packages.config ├── pch.cpp └── pch.h ├── glTF-DXViewer.sln ├── gltfparser ├── dllmain.cpp ├── gltfparser.vcxproj ├── gltfparser.vcxproj.filters ├── packages.config └── stdafx.cpp └── img ├── screenshot1.PNG ├── screenshot2.PNG └── selective-rendering.png /GLBGLTFConverter/GLBGLTFConverter.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/GLBGLTFConverter/GLBGLTFConverter.cpp -------------------------------------------------------------------------------- /GLBGLTFConverter/GLBGLTFConverter.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | 26 | 27 | Source Files 28 | 29 | 30 | Source Files 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /GLBGLTFConverter/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /GLBGLTFConverter/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/GLBGLTFConverter/stdafx.cpp -------------------------------------------------------------------------------- /GLBGLTFConverter/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/GLBGLTFConverter/stdafx.h -------------------------------------------------------------------------------- /GLBGLTFConverter/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/GLBGLTFConverter/targetver.h -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 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 | -------------------------------------------------------------------------------- /ModelViewer/App.xaml: -------------------------------------------------------------------------------- 1 |  7 | 8 | 9 | -------------------------------------------------------------------------------- /ModelViewer/App.xaml.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // App.xaml.cpp 3 | // Implementation of the App class. 4 | // 5 | 6 | #include "pch.h" 7 | #include "RootPage.xaml.h" 8 | #include "DirectXPage.xaml.h" 9 | 10 | using namespace ModelViewer; 11 | 12 | using namespace Platform; 13 | using namespace Windows::ApplicationModel; 14 | using namespace Windows::ApplicationModel::Activation; 15 | using namespace Windows::Foundation; 16 | using namespace Windows::Foundation::Collections; 17 | using namespace Windows::Storage; 18 | using namespace Windows::UI::Xaml; 19 | using namespace Windows::UI::Xaml::Controls; 20 | using namespace Windows::UI::Xaml::Controls::Primitives; 21 | using namespace Windows::UI::Xaml::Data; 22 | using namespace Windows::UI::Xaml::Input; 23 | using namespace Windows::UI::Xaml::Interop; 24 | using namespace Windows::UI::Xaml::Media; 25 | using namespace Windows::UI::Xaml::Navigation; 26 | /// 27 | /// Initializes the singleton application object. This is the first line of authored code 28 | /// executed, and as such is the logical equivalent of main() or WinMain(). 29 | /// 30 | App::App() 31 | { 32 | InitializeComponent(); 33 | 34 | //builder.registerType<> 35 | 36 | Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending); 37 | Resuming += ref new EventHandler(this, &App::OnResuming); 38 | } 39 | 40 | void App::ExtendAcrylicIntoTitleBar() 41 | { 42 | Windows::ApplicationModel::Core::CoreApplication::GetCurrentView()->TitleBar->ExtendViewIntoTitleBar = true; 43 | auto titleBar = Windows::ApplicationModel::Core::CoreApplication::GetCurrentView()->TitleBar; 44 | // These properties don't exist... 45 | //titleBar->ButtonBackgroundColor = Colors.Transparent; 46 | //titleBar->ButtonInactiveBackgroundColor = Colors.Transparent; 47 | } 48 | 49 | /// 50 | /// Invoked when the application is launched normally by the end user. Other entry points 51 | /// will be used when the application is launched to open a specific file, to display 52 | /// search results, and so forth. 53 | /// 54 | /// Details about the launch request and process. 55 | void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ e) 56 | { 57 | #if _DEBUG 58 | if (IsDebuggerPresent()) 59 | { 60 | DebugSettings->EnableFrameRateCounter = true; 61 | } 62 | #endif 63 | 64 | if (m_rootPage == nullptr) 65 | { 66 | m_rootPage = ref new ModelViewer::RootPage(); 67 | } 68 | 69 | if (e->PreviousExecutionState == ApplicationExecutionState::Terminated) 70 | { 71 | m_rootPage->LoadInternalState(ApplicationData::Current->LocalSettings->Values); 72 | } 73 | 74 | auto rootFrame = dynamic_cast(Window::Current->Content); 75 | 76 | // Do not repeat app initialization when the Window already has content, 77 | // just ensure that the window is active 78 | if (rootFrame == nullptr) 79 | { 80 | // Create a Frame to act as the navigation context and associate it with 81 | // a SuspensionManager key 82 | rootFrame = ref new Frame(); 83 | 84 | rootFrame->NavigationFailed += ref new Windows::UI::Xaml::Navigation::NavigationFailedEventHandler(this, &App::OnNavigationFailed); 85 | 86 | if (rootFrame->Content == nullptr) 87 | { 88 | // When the navigation stack isn't restored navigate to the first page, 89 | // configuring the new page by passing required information as a navigation 90 | // parameter 91 | rootFrame->Navigate(TypeName(RootPage::typeid), e->Arguments); 92 | } 93 | 94 | // Place the frame in the current Window 95 | Window::Current->Content = rootFrame; 96 | // Ensure the current window is active 97 | Window::Current->Activate(); 98 | } 99 | else 100 | { 101 | if (rootFrame->Content == nullptr) 102 | { 103 | // When the navigation stack isn't restored navigate to the first page, 104 | // configuring the new page by passing required information as a navigation 105 | // parameter 106 | rootFrame->Navigate(TypeName(RootPage::typeid), e->Arguments); 107 | } 108 | 109 | 110 | // Ensure the current window is active 111 | Window::Current->Activate(); 112 | ExtendAcrylicIntoTitleBar(); 113 | } 114 | 115 | //m_rootPage->GetContentFrame()->Content = ref new DirectXPage(); 116 | } 117 | 118 | /// 119 | /// Invoked when application execution is being suspended. Application state is saved 120 | /// without knowing whether the application will be terminated or resumed with the contents 121 | /// of memory still intact. 122 | /// 123 | /// The source of the suspend request. 124 | /// Details about the suspend request. 125 | void App::OnSuspending(Object^ sender, SuspendingEventArgs^ e) 126 | { 127 | (void) sender; // Unused parameter 128 | (void) e; // Unused parameter 129 | 130 | m_rootPage->SaveInternalState(ApplicationData::Current->LocalSettings->Values); 131 | } 132 | 133 | /// 134 | /// Invoked when application execution is being resumed. 135 | /// 136 | /// The source of the resume request. 137 | /// Details about the resume request. 138 | void App::OnResuming(Object ^sender, Object ^args) 139 | { 140 | (void) sender; // Unused parameter 141 | (void) args; // Unused parameter 142 | 143 | m_rootPage->LoadInternalState(ApplicationData::Current->LocalSettings->Values); 144 | } 145 | 146 | /// 147 | /// Invoked when Navigation to a certain page fails 148 | /// 149 | /// The Frame which failed navigation 150 | /// Details about the navigation failure 151 | void App::OnNavigationFailed(Platform::Object ^sender, Windows::UI::Xaml::Navigation::NavigationFailedEventArgs ^e) 152 | { 153 | throw ref new FailureException("Failed to load Page " + e->SourcePageType.Name); 154 | } 155 | 156 | -------------------------------------------------------------------------------- /ModelViewer/App.xaml.h: -------------------------------------------------------------------------------- 1 | // 2 | // App.xaml.h 3 | // Declaration of the App class. 4 | // 5 | 6 | #pragma once 7 | 8 | #include "App.g.h" 9 | #include "RootPage.xaml.h" 10 | 11 | namespace ModelViewer 12 | { 13 | /// 14 | /// Provides application-specific behavior to supplement the default Application class. 15 | /// 16 | ref class App sealed 17 | { 18 | public: 19 | App(); 20 | virtual void OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ e) override; 21 | 22 | private: 23 | void ExtendAcrylicIntoTitleBar(); 24 | 25 | void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ e); 26 | void OnResuming(Platform::Object ^sender, Platform::Object ^args); 27 | void OnNavigationFailed(Platform::Object ^sender, Windows::UI::Xaml::Navigation::NavigationFailedEventArgs ^e); 28 | RootPage^ m_rootPage; 29 | }; 30 | } 31 | -------------------------------------------------------------------------------- /ModelViewer/Assets/LockScreenLogo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/LockScreenLogo.scale-200.png -------------------------------------------------------------------------------- /ModelViewer/Assets/Shaders/pbrvertex.hlsl: -------------------------------------------------------------------------------- 1 | //#define NORMALS 2 | //#define UV 3 | 4 | // A constant buffer that stores the three basic column-major matrices for composing geometry. 5 | cbuffer ModelViewProjectionConstantBuffer : register(b0) 6 | { 7 | matrix model; 8 | matrix view; 9 | matrix projection; 10 | }; 11 | 12 | // Per-vertex data used as input to the vertex shader. 13 | struct VertexShaderInput 14 | { 15 | float4 position : POSITION; 16 | #ifdef NORMALS 17 | float3 normal : NORMAL; 18 | #endif 19 | #ifdef UV 20 | float2 texcoord : TEXCOORD0; 21 | #endif 22 | }; 23 | 24 | // Per-pixel color data passed through the pixel shader. 25 | struct PixelShaderInput 26 | { 27 | float4 position : SV_POSITION; 28 | float3 poswithoutw : POSITION; 29 | 30 | #ifdef NORMALS 31 | float3 normal : NORMAL; 32 | #endif 33 | 34 | float2 texcoord : TEXCOORD0; 35 | }; 36 | 37 | PixelShaderInput main(VertexShaderInput input) 38 | { 39 | PixelShaderInput output; 40 | 41 | // Transform the vertex position into projected space. 42 | float4 pos = mul(input.position, model); 43 | output.poswithoutw = float3(pos.xyz) / pos.w; 44 | 45 | #ifdef NORMALS 46 | // If we have normals... 47 | output.normal = normalize(mul(float4(input.normal.xyz, 0.0), model)); 48 | #endif 49 | 50 | #ifdef UV 51 | output.texcoord = input.texcoord; 52 | #else 53 | output.texcoord = float2(0.0f, 0.0f); 54 | #endif 55 | 56 | #ifdef HAS_NORMALS 57 | #ifdef HAS_TANGENTS 58 | vec3 normalW = normalize(vec3(u_ModelMatrix * vec4(a_Normal.xyz, 0.0))); 59 | vec3 tangentW = normalize(vec3(u_ModelMatrix * vec4(a_Tangent.xyz, 0.0))); 60 | vec3 bitangentW = cross(normalW, tangentW) * a_Tangent.w; 61 | v_TBN = mat3(tangentW, bitangentW, normalW); 62 | #else // HAS_TANGENTS != 1 63 | v_Normal = normalize(vec3(u_ModelMatrix * vec4(a_Normal.xyz, 0.0))); 64 | #endif 65 | #endif 66 | 67 | // Transform the vertex position into projected space. 68 | pos = mul(pos, view); 69 | pos = mul(pos, projection); 70 | output.position = pos; 71 | 72 | return output; 73 | } -------------------------------------------------------------------------------- /ModelViewer/Assets/SplashScreen.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/SplashScreen.scale-200.png -------------------------------------------------------------------------------- /ModelViewer/Assets/Square150x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/Square150x150Logo.scale-200.png -------------------------------------------------------------------------------- /ModelViewer/Assets/Square44x44Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/Square44x44Logo.scale-200.png -------------------------------------------------------------------------------- /ModelViewer/Assets/Square44x44Logo.targetsize-24_altform-unplated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/Square44x44Logo.targetsize-24_altform-unplated.png -------------------------------------------------------------------------------- /ModelViewer/Assets/StoreLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/StoreLogo.png -------------------------------------------------------------------------------- /ModelViewer/Assets/Wide310x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/Wide310x150Logo.scale-200.png -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/brdfLUT.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/brdfLUT.png -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/diffuse/diffuse_back_0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/diffuse/diffuse_back_0.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/diffuse/diffuse_bottom_0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/diffuse/diffuse_bottom_0.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/diffuse/diffuse_front_0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/diffuse/diffuse_front_0.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/diffuse/diffuse_left_0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/diffuse/diffuse_left_0.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/diffuse/diffuse_right_0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/diffuse/diffuse_right_0.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/diffuse/diffuse_top_0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/diffuse/diffuse_top_0.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/environment/environment_back_0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/environment/environment_back_0.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/environment/environment_bottom_0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/environment/environment_bottom_0.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/environment/environment_front_0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/environment/environment_front_0.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/environment/environment_left_0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/environment/environment_left_0.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/environment/environment_right_0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/environment/environment_right_0.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/environment/environment_top_0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/environment/environment_top_0.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_back_0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_back_0.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_back_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_back_1.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_back_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_back_2.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_back_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_back_3.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_back_4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_back_4.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_back_5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_back_5.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_back_6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_back_6.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_back_7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_back_7.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_back_8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_back_8.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_back_9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_back_9.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_bottom_0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_bottom_0.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_bottom_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_bottom_1.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_bottom_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_bottom_2.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_bottom_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_bottom_3.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_bottom_4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_bottom_4.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_bottom_5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_bottom_5.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_bottom_6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_bottom_6.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_bottom_7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_bottom_7.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_bottom_8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_bottom_8.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_bottom_9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_bottom_9.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_front_0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_front_0.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_front_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_front_1.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_front_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_front_2.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_front_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_front_3.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_front_4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_front_4.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_front_5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_front_5.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_front_6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_front_6.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_front_7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_front_7.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_front_8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_front_8.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_front_9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_front_9.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_left_0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_left_0.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_left_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_left_1.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_left_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_left_2.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_left_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_left_3.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_left_4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_left_4.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_left_5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_left_5.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_left_6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_left_6.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_left_7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_left_7.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_left_8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_left_8.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_left_9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_left_9.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_right_0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_right_0.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_right_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_right_1.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_right_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_right_2.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_right_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_right_3.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_right_4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_right_4.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_right_5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_right_5.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_right_6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_right_6.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_right_7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_right_7.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_right_8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_right_8.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_right_9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_right_9.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_top_0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_top_0.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_top_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_top_1.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_top_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_top_2.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_top_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_top_3.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_top_4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_top_4.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_top_5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_top_5.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_top_6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_top_6.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_top_7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_top_7.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_top_8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_top_8.jpg -------------------------------------------------------------------------------- /ModelViewer/Assets/textures/papermill/specular/specular_top_9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/ModelViewer/Assets/textures/papermill/specular/specular_top_9.jpg -------------------------------------------------------------------------------- /ModelViewer/Axis.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "Axis.h" 3 | #include "Content\ShaderStructures.h" 4 | #include "Common\DirectXHelper.h" 5 | 6 | using namespace ModelViewer; 7 | using namespace DirectX; 8 | 9 | Axis::Axis(float axisLength) : _axisLength(axisLength) 10 | { 11 | } 12 | 13 | void Axis::Initialise(ID3D11Device *device) 14 | { 15 | D3D11_BUFFER_DESC vertexBufferDesc, indexBufferDesc; 16 | D3D11_SUBRESOURCE_DATA vertexData, indexData; 17 | 18 | XMFLOAT3 colour = { 1.0f, 1.0f, 1.0f }; 19 | static const VertexPositionColor vertices [] = 20 | { 21 | { XMFLOAT3(0.0f, _axisLength, 0.0f), colour }, 22 | { XMFLOAT3(0.0f, -_axisLength, 0.0f), colour }, 23 | { XMFLOAT3(-_axisLength, 0.0f, 0.0f), colour }, 24 | { XMFLOAT3(_axisLength, 0.0f, 0.0f), colour }, 25 | { XMFLOAT3(0.0f, 0.0f, -_axisLength), colour }, 26 | { XMFLOAT3(0.0f, 0.0f, _axisLength), colour }, 27 | }; 28 | m_vertexCount = 6; 29 | 30 | static const unsigned long axisIndices [] = 31 | { 32 | 0, 1, 2, 3, 4, 5 33 | }; 34 | m_indexCount = 6; 35 | 36 | // Set up the description of the static vertex buffer. 37 | vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT; 38 | vertexBufferDesc.ByteWidth = sizeof(VertexPositionColor) * m_vertexCount; 39 | vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; 40 | vertexBufferDesc.CPUAccessFlags = 0; 41 | vertexBufferDesc.MiscFlags = 0; 42 | vertexBufferDesc.StructureByteStride = 0; 43 | 44 | // Give the subresource structure a pointer to the vertex data. 45 | vertexData.pSysMem = vertices; 46 | vertexData.SysMemPitch = 0; 47 | vertexData.SysMemSlicePitch = 0; 48 | 49 | // Now create the vertex buffer. 50 | DX::ThrowIfFailed(device->CreateBuffer(&vertexBufferDesc, &vertexData, m_vertexBuffer.GetAddressOf())); 51 | 52 | // Set up the description of the static index buffer. 53 | indexBufferDesc.Usage = D3D11_USAGE_DEFAULT; 54 | indexBufferDesc.ByteWidth = sizeof(unsigned long) * m_indexCount; 55 | indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER; 56 | indexBufferDesc.CPUAccessFlags = 0; 57 | indexBufferDesc.MiscFlags = 0; 58 | indexBufferDesc.StructureByteStride = 0; 59 | 60 | // Give the subresource structure a pointer to the index data. 61 | indexData.pSysMem = axisIndices; 62 | indexData.SysMemPitch = 0; 63 | indexData.SysMemSlicePitch = 0; 64 | 65 | // Create the index buffer. 66 | DX::ThrowIfFailed(device->CreateBuffer(&indexBufferDesc, &indexData, m_indexBuffer.GetAddressOf())); 67 | 68 | D3D11_RASTERIZER_DESC rasterizerState; 69 | rasterizerState.FillMode = D3D11_FILL_WIREFRAME; 70 | rasterizerState.CullMode = D3D11_CULL_NONE; 71 | rasterizerState.FrontCounterClockwise = true; 72 | rasterizerState.DepthBias = 10; 73 | rasterizerState.DepthBiasClamp = 0; 74 | rasterizerState.SlopeScaledDepthBias = 0.0; 75 | rasterizerState.DepthClipEnable = false; 76 | rasterizerState.ScissorEnable = false; 77 | rasterizerState.MultisampleEnable = true; 78 | rasterizerState.AntialiasedLineEnable = true; 79 | DX::ThrowIfFailed(device->CreateRasterizerState(&rasterizerState, &_pRasterState)); 80 | } 81 | 82 | void Axis::RenderBuffers(ID3D11DeviceContext* deviceContext) 83 | { 84 | unsigned int stride; 85 | unsigned int offset; 86 | 87 | // Set vertex buffer stride and offset. 88 | stride = sizeof(VertexPositionColor); 89 | offset = 0; 90 | 91 | auto vb = m_vertexBuffer.Get(); 92 | 93 | // Set the vertex buffer to active in the input assembler so it can be rendered. 94 | deviceContext->IASetVertexBuffers(0, 1, &vb, &stride, &offset); 95 | 96 | // Set the index buffer to active in the input assembler so it can be rendered. 97 | deviceContext->IASetIndexBuffer(m_indexBuffer.Get(), DXGI_FORMAT_R32_UINT, 0); 98 | 99 | //Set the render format to line list. 100 | // Set the type of primitive that should be rendered from this vertex buffer, in this case a line list. 101 | deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST); 102 | deviceContext->RSSetState(_pRasterState.Get()); 103 | } 104 | 105 | -------------------------------------------------------------------------------- /ModelViewer/Axis.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | using namespace Microsoft::WRL; 4 | 5 | class Axis 6 | { 7 | public: 8 | Axis(float axisLength); 9 | void Initialise(ID3D11Device *device); 10 | void RenderBuffers(ID3D11DeviceContext* deviceContext); 11 | int IndexCount() { return m_indexCount; }; 12 | 13 | private: 14 | float _axisLength; 15 | int m_vertexCount; 16 | int m_indexCount; 17 | ComPtr m_vertexBuffer, m_indexBuffer; 18 | //ID3D11Buffer *m_vertexBuffer, *m_indexBuffer; 19 | ComPtr _pRasterState; 20 | }; 21 | 22 | -------------------------------------------------------------------------------- /ModelViewer/BooleanToVisibilityConverter.cpp: -------------------------------------------------------------------------------- 1 | //********************************************************* 2 | // 3 | // Copyright (c) Microsoft. All rights reserved. 4 | // This code is licensed under the MIT License (MIT). 5 | // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF 6 | // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY 7 | // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR 8 | // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. 9 | // 10 | //********************************************************* 11 | #include "pch.h" 12 | #include "BooleanToVisibilityConverter.h" 13 | 14 | using namespace ModelViewer; 15 | 16 | using namespace Platform; 17 | using namespace Windows::UI::Xaml; 18 | using namespace Windows::UI::Xaml::Interop; 19 | 20 | BooleanToVisibilityConverter::BooleanToVisibilityConverter() 21 | { 22 | } 23 | 24 | Object^ BooleanToVisibilityConverter::Convert(Object ^value, TypeName targetType, Object ^parameter, String ^language) 25 | { 26 | IBox^ visibility = dynamic_cast^>(value); 27 | if (visibility != nullptr && visibility->Value != IsInverse) 28 | { 29 | return Visibility::Visible; 30 | } 31 | else 32 | { 33 | return Visibility::Collapsed; 34 | } 35 | } 36 | 37 | Object ^ BooleanToVisibilityConverter::ConvertBack(Object ^value, TypeName targetType, Object ^parameter, String ^language) 38 | { 39 | throw ref new NotImplementedException(); 40 | } 41 | -------------------------------------------------------------------------------- /ModelViewer/BooleanToVisibilityConverter.h: -------------------------------------------------------------------------------- 1 | //********************************************************* 2 | // 3 | // Copyright (c) Microsoft. All rights reserved. 4 | // This code is licensed under the MIT License (MIT). 5 | // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF 6 | // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY 7 | // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR 8 | // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. 9 | // 10 | //********************************************************* 11 | #pragma once 12 | namespace ModelViewer 13 | { 14 | [Windows::UI::Xaml::Data::Bindable] 15 | [Windows::Foundation::Metadata::WebHostHidden] 16 | public ref class BooleanToVisibilityConverter sealed : Windows::UI::Xaml::Data::IValueConverter 17 | { 18 | public: 19 | BooleanToVisibilityConverter(); 20 | 21 | // Inherited via IValueConverter 22 | virtual Platform::Object^ Convert(Platform::Object ^value, Windows::UI::Xaml::Interop::TypeName targetType, Platform::Object ^parameter, Platform::String ^language); 23 | virtual Platform::Object^ ConvertBack(Platform::Object ^value, Windows::UI::Xaml::Interop::TypeName targetType, Platform::Object ^parameter, Platform::String ^language); 24 | 25 | property bool IsInverse 26 | { 27 | bool get() { return isInverse; } 28 | void set(bool value) { isInverse = value; } 29 | } 30 | private: 31 | bool isInverse = false; 32 | }; 33 | } 34 | 35 | -------------------------------------------------------------------------------- /ModelViewer/BoundingBox.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "BoundingBox.h" 3 | 4 | 5 | -------------------------------------------------------------------------------- /ModelViewer/BoundingBox.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "DirectXMath.h" 3 | 4 | using namespace DirectX; 5 | 6 | template 7 | class BoundingBox 8 | { 9 | public: 10 | BoundingBox() : 11 | MinX((numeric_limits::max)()), 12 | MaxX((numeric_limits::min)()), 13 | MinY((numeric_limits::max)()), 14 | MaxY((numeric_limits::min)()), 15 | MinZ((numeric_limits::max)()), 16 | MaxZ((numeric_limits::min)()) 17 | { 18 | } 19 | 20 | XMFLOAT3 Centre() 21 | { 22 | XMFLOAT3 ret; 23 | ret.x = bbox.MinX + (bbox.MaxX - bbox.MinX) * 0.5f; 24 | ret.y = bbox.MinY + (bbox.MaxY - bbox.MinY) * 0.5f; 25 | ret.z = bbox.MinZ + (bbox.MaxZ - bbox.MinZ) * 0.5f; 26 | return ret; 27 | } 28 | 29 | void Grow(BoundingBox& other) 30 | { 31 | MinX = min(MinX, other.MinX); 32 | MinY = min(MinY, other.MinY); 33 | MinZ = min(MinZ, other.MinZ); 34 | 35 | MaxX = max(MaxX, other.MaxX); 36 | MaxY = max(MaxY, other.MaxY); 37 | MaxZ = max(MaxZ, other.MaxZ); 38 | } 39 | 40 | static BoundingBox CreateBoundingBoxFromVertexBuffer(void *buffer, size_t bufferSize) 41 | { 42 | XMFLOAT3 *buffPtr = (XMFLOAT3 *)buffer; 43 | BoundingBox bbox; 44 | for (size_t i = 0; i < bufferSize / (3 * sizeof(float)); i++, buffPtr++) 45 | { 46 | bbox.MaxX = max(buffPtr->x, bbox.MaxX); 47 | bbox.MaxY = max(buffPtr->y, bbox.MaxY); 48 | bbox.MaxZ = max(buffPtr->z, bbox.MaxZ); 49 | bbox.MinX = min(buffPtr->x, bbox.MinX); 50 | bbox.MinY = min(buffPtr->y, bbox.MinY); 51 | bbox.MinZ = min(buffPtr->z, bbox.MinZ); 52 | } 53 | return bbox; 54 | } 55 | 56 | T MinX; 57 | T MaxX; 58 | T MinY; 59 | T MaxY; 60 | T MinZ; 61 | T MaxZ; 62 | }; 63 | 64 | -------------------------------------------------------------------------------- /ModelViewer/BufferCache.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "BufferCache.h" 3 | 4 | size_t BufferDescriptor::Hash() 5 | { 6 | if (!_hashCalculated) 7 | { 8 | hash bufferHash; 9 | _hash = bufferHash(*this); 10 | _hashCalculated = true; 11 | } 12 | return _hash; 13 | } -------------------------------------------------------------------------------- /ModelViewer/BufferCache.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "BoundingBox.h" 4 | #include "Common\DirectXHelper.h" 5 | 6 | using namespace Microsoft::WRL; 7 | using namespace DX; 8 | 9 | class BufferDescriptor 10 | { 11 | public: 12 | BufferDescriptor(GLTF_BufferData ^ data, shared_ptr deviceResources) : 13 | _data(data), 14 | _deviceResources(deviceResources) 15 | { 16 | } 17 | shared_ptr DevResources() { return _deviceResources; } 18 | const shared_ptr DevResources() const { return _deviceResources; } 19 | 20 | size_t Hash(); 21 | 22 | const wchar_t *ContentType() const { return _data->BufferDescription->BufferContentType->Data(); } 23 | unsigned int AccessorIdx() const { return _data->BufferDescription->accessorIdx; } 24 | 25 | GLTF_BufferData^ Data() { return _data; } 26 | 27 | private: 28 | bool _hashCalculated = false; 29 | shared_ptr _deviceResources; 30 | size_t _hash; 31 | unsigned int _accessorIdx; 32 | GLTF_BufferData ^ _data; 33 | }; 34 | 35 | template <> 36 | struct hash 37 | { 38 | size_t operator()(const BufferDescriptor& descriptor) const 39 | { 40 | size_t res = 0; 41 | hash myHash; 42 | res ^= myHash(descriptor.ContentType()); 43 | hash myHash2; 44 | res ^= myHash2(descriptor.AccessorIdx()); 45 | return res; 46 | } 47 | }; 48 | 49 | //class BufferWrapper 50 | //{ 51 | //public: 52 | // BufferWrapper(GLTF_BufferData^ data, ComPtr buffer) : 53 | // _data(data), 54 | // _buffer(buffer) 55 | // { 56 | // } 57 | // BufferWrapper() {} 58 | // ComPtr& Buffer() { return _buffer; } 59 | // 60 | // GLTF_BufferData^ Data() { return _data; } 61 | // 62 | //private: 63 | // GLTF_BufferData ^ _data; 64 | // ComPtr _buffer; 65 | //}; 66 | 67 | class ID3D11BufferWrapper 68 | { 69 | public: 70 | static shared_ptr Create(BufferDescriptor descriptor) 71 | { 72 | auto ret = make_shared(); 73 | 74 | int bindFlags = 0; 75 | if (descriptor.Data()->BufferDescription->BufferContentType == L"POSITION" || 76 | descriptor.Data()->BufferDescription->BufferContentType == L"NORMAL" || 77 | descriptor.Data()->BufferDescription->BufferContentType == L"TEXCOORD_0") 78 | { 79 | bindFlags = D3D11_BIND_VERTEX_BUFFER; 80 | } 81 | else if (descriptor.Data()->BufferDescription->BufferContentType == L"INDICES") 82 | { 83 | bindFlags = D3D11_BIND_INDEX_BUFFER; 84 | } 85 | else 86 | { 87 | /*throw new std::exception("Unknown Buffer Type");*/ 88 | return ret; 89 | } 90 | 91 | if (descriptor.Data()->BufferDescription->BufferContentType == L"POSITION") 92 | { 93 | ret->SetBoundingBox( 94 | BoundingBox::CreateBoundingBoxFromVertexBuffer( 95 | (void *)descriptor.Data()->BufferDescription->pSysMem, descriptor.Data()->SubResource->ByteWidth) 96 | ); 97 | } 98 | 99 | // Create the buffers... 100 | D3D11_SUBRESOURCE_DATA vertexBufferData = { 0 }; 101 | vertexBufferData.pSysMem = (void *)descriptor.Data()->BufferDescription->pSysMem; 102 | vertexBufferData.SysMemPitch = 0; 103 | vertexBufferData.SysMemSlicePitch = 0; 104 | 105 | CD3D11_BUFFER_DESC vertexBufferDesc(static_cast(descriptor.Data()->SubResource->ByteWidth), bindFlags); 106 | vertexBufferDesc.StructureByteStride = static_cast(descriptor.Data()->SubResource->StructureByteStride); 107 | 108 | auto device = descriptor.DevResources()->GetD3DDevice(); 109 | ThrowIfFailed(device->CreateBuffer(&vertexBufferDesc, &vertexBufferData, ret->AddressOfBuffer())); 110 | //descriptor.DevResources()->GetD3DDeviceContext()->Flush(); 111 | return ret; 112 | } 113 | 114 | BoundingBox& GetBoundingBox() { return _bbox; } 115 | void SetBoundingBox(BoundingBox bbox) { _bbox = bbox; } 116 | 117 | ComPtr& Buffer() { return _buffer; } 118 | ID3D11Buffer **AddressOfBuffer() { return _buffer.GetAddressOf(); } 119 | 120 | private: 121 | BoundingBox _bbox; 122 | ComPtr _buffer; 123 | }; 124 | 125 | template 126 | class BufferCache 127 | { 128 | public: 129 | BufferCache() {}; 130 | ~BufferCache() {}; 131 | 132 | shared_ptr FindOrCreateBuffer(BufferDescriptor descriptor) 133 | { 134 | // get the hash value... 135 | size_t hash = descriptor.Hash(); 136 | map>::iterator res = _buffers.find(hash); 137 | if (res != _buffers.end()) 138 | return (*res).second; 139 | 140 | auto ret = TBufferWrapper::Create(descriptor); 141 | _buffers[hash] = ret; 142 | return ret; 143 | } 144 | 145 | private: 146 | map> _buffers; 147 | }; 148 | 149 | -------------------------------------------------------------------------------- /ModelViewer/BufferManager.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "BufferManager.h" 3 | 4 | BufferManager::BufferManager() : 5 | _cbPerObject(0), 6 | _cbPerFrame(1), 7 | _mvpBuffer(0) 8 | { 9 | } -------------------------------------------------------------------------------- /ModelViewer/BufferManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Content\ShaderStructures.h" 4 | #include "Common\DirectXHelper.h" 5 | #include "Common\DeviceResources.h" 6 | 7 | using namespace ModelViewer; 8 | using namespace Microsoft::WRL; 9 | using namespace DX; 10 | 11 | template 12 | class ConstantBufferData 13 | { 14 | public: 15 | ConstantBufferData(unsigned int slot) : 16 | _slot(slot) 17 | { 18 | } 19 | 20 | ~ConstantBufferData() 21 | { 22 | m_constantBuffer.Reset(); 23 | } 24 | 25 | void Initialise(const DeviceResources& devResources) 26 | { 27 | CD3D11_BUFFER_DESC desc(sizeof(T), D3D11_BIND_CONSTANT_BUFFER); 28 | auto device = devResources.GetD3DDevice(); 29 | DX::ThrowIfFailed(device->CreateBuffer(&desc, nullptr, &m_constantBuffer)); 30 | } 31 | void Release() { m_constantBuffer.Reset(); } 32 | void Update(const DeviceResources& devResources) 33 | { 34 | if (m_constantBuffer == nullptr) 35 | return; 36 | 37 | assert(ConstantBuffer().Get()); 38 | auto context = devResources.GetD3DDeviceContext(); 39 | context->UpdateSubresource1(ConstantBuffer().Get(), 0, NULL, &(BufferData()), 0, 0, 0); 40 | } 41 | 42 | T& BufferData() { return _bufferData; } 43 | ComPtr ConstantBuffer() { return m_constantBuffer; } 44 | 45 | private: 46 | unsigned int _slot; 47 | T _bufferData; 48 | ComPtr m_constantBuffer; 49 | }; 50 | 51 | class BufferManager : public Singleton 52 | { 53 | friend class Singleton; 54 | 55 | public: 56 | ConstantBufferData& MVPBuffer() 57 | { 58 | return _mvpBuffer; 59 | } 60 | ConstantBufferData& PerObjBuffer() 61 | { 62 | return _cbPerObject; 63 | } 64 | ConstantBufferData& PerFrameBuffer() 65 | { 66 | return _cbPerFrame; 67 | } 68 | 69 | protected: 70 | BufferManager(); 71 | 72 | private: 73 | ConstantBufferData _mvpBuffer; 74 | ConstantBufferData _cbPerObject; 75 | ConstantBufferData _cbPerFrame; 76 | }; 77 | 78 | -------------------------------------------------------------------------------- /ModelViewer/ClassDiagram.cd: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | AAQAAAAAAIAAEwASEAIAAAQgAEAAAEEAIIEAQAIAAEA= 7 | Scene\GraphNode.h 8 | 9 | 10 | 11 | 12 | 13 | 34 | 35 | 36 | 37 | 38 | AQSwIIAAAYGAE0ASBYKgAQQgAEAECEkgIINAY5IBADA= 39 | Scene\GraphContainerNode.h 40 | 41 | 42 | 43 | 44 | 45 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | Scene\MeshNode.h 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | AACACAAAQIAAA0ACwAAAAQAAAEAEAEFACEAADAIAAAA= 67 | Scene\MeshNode.h 68 | 69 | 70 | 71 | 72 | 73 | AAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAA= 74 | Scene\CameraNode.h 75 | 76 | 77 | 78 | 79 | 80 | AAAAAAAAAAQAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAA= 81 | Scene\LightNode.h 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /ModelViewer/Common/BindableBase.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "BindableBase.h" 3 | 4 | #include 5 | #include 6 | 7 | using namespace Common; 8 | 9 | using namespace Platform; 10 | using namespace Windows::UI::Xaml::Data; 11 | 12 | String^ BindableBase::getCallerName(const char* funName) 13 | { 14 | std::string str(funName); 15 | std::regex regex("(\\w+)(?=\\:\\:)|(?!\\:\\:)(\\w+)"); 16 | std::sregex_iterator it(str.begin(), str.end(), regex); 17 | std::sregex_iterator it_end; 18 | 19 | std::vector vec; 20 | 21 | while (it != it_end) 22 | { 23 | vec.push_back((*it).str()); 24 | ++it; 25 | } 26 | 27 | std::string last = *(std::end(vec) - 1); 28 | std::wstring ws(last.begin(), last.end()); 29 | 30 | //if property - get the one before last 31 | if (last.compare("set") || last.compare("get")) { 32 | std::string one_before_last = *(std::end(vec) - 2); 33 | ws.assign(one_before_last.begin(), one_before_last.end()); 34 | } 35 | 36 | return ref new String(ws.c_str()); 37 | } 38 | 39 | void BindableBase::OnPropertyChanged(String^ value) 40 | { 41 | PropertyChanged(this, ref new PropertyChangedEventArgs(value)); 42 | } -------------------------------------------------------------------------------- /ModelViewer/Common/BindableBase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Common 4 | { 5 | namespace WUX = Windows::UI::Xaml; 6 | namespace WUXD = Windows::UI::Xaml::Data; 7 | 8 | public ref class BindableBase : public WUXD::INotifyPropertyChanged, WUX::DependencyObject 9 | { 10 | public: 11 | virtual event WUXD::PropertyChangedEventHandler^ PropertyChanged; 12 | 13 | internal: 14 | Platform::String^ getCallerName(const char* funName); 15 | 16 | protected: 17 | virtual void OnPropertyChanged(Platform::String^ value); 18 | }; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /ModelViewer/Common/DeviceResources.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace DX 4 | { 5 | // Provides an interface for an application that owns DeviceResources to be notified of the device being lost or created. 6 | interface IDeviceNotify 7 | { 8 | virtual void OnDeviceLost() = 0; 9 | virtual void OnDeviceRestored() = 0; 10 | }; 11 | 12 | // Controls all the DirectX device resources. 13 | class DeviceResources 14 | { 15 | public: 16 | DeviceResources(); 17 | void SetSwapChainPanel(Windows::UI::Xaml::Controls::SwapChainPanel^ panel); 18 | void SetLogicalSize(Windows::Foundation::Size logicalSize); 19 | void SetCurrentOrientation(Windows::Graphics::Display::DisplayOrientations currentOrientation); 20 | void SetDpi(float dpi); 21 | void SetCompositionScale(float compositionScaleX, float compositionScaleY); 22 | void ValidateDevice(); 23 | void HandleDeviceLost(); 24 | void RegisterDeviceNotify(IDeviceNotify* deviceNotify); 25 | void Trim(); 26 | void Present(); 27 | 28 | // The size of the render target, in pixels. 29 | Windows::Foundation::Size GetOutputSize() const { return m_outputSize; } 30 | 31 | // The size of the render target, in dips. 32 | Windows::Foundation::Size GetLogicalSize() const { return m_logicalSize; } 33 | float GetDpi() const { return m_effectiveDpi; } 34 | 35 | // D3D Accessors. 36 | ID3D11Device3* GetD3DDevice() const { return m_d3dDevice.Get(); } 37 | ID3D11DeviceContext3* GetD3DDeviceContext() const { return m_d3dContext.Get(); } 38 | IDXGISwapChain3* GetSwapChain() const { return m_swapChain.Get(); } 39 | D3D_FEATURE_LEVEL GetDeviceFeatureLevel() const { return m_d3dFeatureLevel; } 40 | ID3D11RenderTargetView1* GetBackBufferRenderTargetView() const { return m_d3dRenderTargetView.Get(); } 41 | ID3D11DepthStencilView* GetDepthStencilView() const { return m_d3dDepthStencilView.Get(); } 42 | D3D11_VIEWPORT GetScreenViewport() const { return m_screenViewport; } 43 | DirectX::XMFLOAT4X4 GetOrientationTransform3D() const { return m_orientationTransform3D; } 44 | 45 | // D2D Accessors. 46 | ID2D1Factory3* GetD2DFactory() const { return m_d2dFactory.Get(); } 47 | ID2D1Device2* GetD2DDevice() const { return m_d2dDevice.Get(); } 48 | ID2D1DeviceContext2* GetD2DDeviceContext() const { return m_d2dContext.Get(); } 49 | ID2D1Bitmap1* GetD2DTargetBitmap() const { return m_d2dTargetBitmap.Get(); } 50 | IDWriteFactory3* GetDWriteFactory() const { return m_dwriteFactory.Get(); } 51 | IWICImagingFactory2* GetWicImagingFactory() const { return m_wicFactory.Get(); } 52 | D2D1::Matrix3x2F GetOrientationTransform2D() const { return m_orientationTransform2D; } 53 | 54 | private: 55 | void CreateDeviceIndependentResources(); 56 | void CreateDeviceResources(); 57 | void CreateWindowSizeDependentResources(); 58 | void UpdateRenderTargetSize(); 59 | DXGI_MODE_ROTATION ComputeDisplayRotation(); 60 | 61 | // Direct3D objects. 62 | Microsoft::WRL::ComPtr m_d3dDevice; 63 | Microsoft::WRL::ComPtr m_d3dContext; 64 | Microsoft::WRL::ComPtr m_swapChain; 65 | 66 | // Direct3D rendering objects. Required for 3D. 67 | Microsoft::WRL::ComPtr m_d3dRenderTargetView; 68 | Microsoft::WRL::ComPtr m_d3dDepthStencilView; 69 | D3D11_VIEWPORT m_screenViewport; 70 | 71 | // Direct2D drawing components. 72 | Microsoft::WRL::ComPtr m_d2dFactory; 73 | Microsoft::WRL::ComPtr m_d2dDevice; 74 | Microsoft::WRL::ComPtr m_d2dContext; 75 | Microsoft::WRL::ComPtr m_d2dTargetBitmap; 76 | 77 | // DirectWrite drawing components. 78 | Microsoft::WRL::ComPtr m_dwriteFactory; 79 | Microsoft::WRL::ComPtr m_wicFactory; 80 | 81 | // Cached reference to the XAML panel. 82 | Windows::UI::Xaml::Controls::SwapChainPanel^ m_swapChainPanel; 83 | 84 | // Cached device properties. 85 | D3D_FEATURE_LEVEL m_d3dFeatureLevel; 86 | Windows::Foundation::Size m_d3dRenderTargetSize; 87 | Windows::Foundation::Size m_outputSize; 88 | Windows::Foundation::Size m_logicalSize; 89 | Windows::Graphics::Display::DisplayOrientations m_nativeOrientation; 90 | Windows::Graphics::Display::DisplayOrientations m_currentOrientation; 91 | float m_dpi; 92 | float m_compositionScaleX; 93 | float m_compositionScaleY; 94 | 95 | // Variables that take into account whether the app supports high resolution screens or not. 96 | float m_effectiveDpi; 97 | float m_effectiveCompositionScaleX; 98 | float m_effectiveCompositionScaleY; 99 | 100 | // Transforms used for display orientation. 101 | D2D1::Matrix3x2F m_orientationTransform2D; 102 | DirectX::XMFLOAT4X4 m_orientationTransform3D; 103 | 104 | // The IDeviceNotify can be held directly as it owns the DeviceResources. 105 | IDeviceNotify* m_deviceNotify; 106 | }; 107 | } -------------------------------------------------------------------------------- /ModelViewer/Common/DirectXHelper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include // For create_task 4 | 5 | namespace DX 6 | { 7 | inline void ThrowIfFailed(HRESULT hr) 8 | { 9 | if (FAILED(hr)) 10 | { 11 | // Set a breakpoint on this line to catch Win32 API errors. 12 | throw Platform::Exception::CreateException(hr); 13 | } 14 | } 15 | 16 | // Function that reads from a binary file asynchronously. 17 | inline Concurrency::task> ReadDataAsync(const std::wstring& filename) 18 | { 19 | using namespace Windows::Storage; 20 | using namespace Concurrency; 21 | 22 | auto folder = Windows::ApplicationModel::Package::Current->InstalledLocation; 23 | 24 | return create_task(folder->GetFileAsync(Platform::StringReference(filename.c_str()))).then([] (StorageFile^ file) 25 | { 26 | return FileIO::ReadBufferAsync(file); 27 | }).then([] (Streams::IBuffer^ fileBuffer) -> std::vector<::byte> 28 | { 29 | std::vector<::byte> returnBuffer; 30 | returnBuffer.resize(fileBuffer->Length); 31 | Streams::DataReader::FromBuffer(fileBuffer)->ReadBytes(Platform::ArrayReference<::byte>(returnBuffer.data(), fileBuffer->Length)); 32 | return returnBuffer; 33 | }); 34 | } 35 | 36 | // Converts a length in device-independent pixels (DIPs) to a length in physical pixels. 37 | inline float ConvertDipsToPixels(float dips, float dpi) 38 | { 39 | static const float dipsPerInch = 96.0f; 40 | return floorf(dips * dpi / dipsPerInch + 0.5f); // Round to nearest integer. 41 | } 42 | 43 | #if defined(_DEBUG) 44 | // Check for SDK Layer support. 45 | inline bool SdkLayersAvailable() 46 | { 47 | HRESULT hr = D3D11CreateDevice( 48 | nullptr, 49 | D3D_DRIVER_TYPE_NULL, // There is no need to create a real hardware device. 50 | 0, 51 | D3D11_CREATE_DEVICE_DEBUG, // Check for the SDK layers. 52 | nullptr, // Any feature level will do. 53 | 0, 54 | D3D11_SDK_VERSION, // Always set this to D3D11_SDK_VERSION for Windows Store apps. 55 | nullptr, // No need to keep the D3D device reference. 56 | nullptr, // No need to know the feature level. 57 | nullptr // No need to keep the D3D device context reference. 58 | ); 59 | 60 | return SUCCEEDED(hr); 61 | } 62 | #endif 63 | } 64 | -------------------------------------------------------------------------------- /ModelViewer/Common/StepTimer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace DX 6 | { 7 | // Helper class for animation and simulation timing. 8 | class StepTimer 9 | { 10 | public: 11 | StepTimer() : 12 | m_elapsedTicks(0), 13 | m_totalTicks(0), 14 | m_leftOverTicks(0), 15 | m_frameCount(0), 16 | m_framesPerSecond(0), 17 | m_framesThisSecond(0), 18 | m_qpcSecondCounter(0), 19 | m_isFixedTimeStep(false), 20 | m_targetElapsedTicks(TicksPerSecond / 60) 21 | { 22 | if (!QueryPerformanceFrequency(&m_qpcFrequency)) 23 | { 24 | throw ref new Platform::FailureException(); 25 | } 26 | 27 | if (!QueryPerformanceCounter(&m_qpcLastTime)) 28 | { 29 | throw ref new Platform::FailureException(); 30 | } 31 | 32 | // Initialize max delta to 1/10 of a second. 33 | m_qpcMaxDelta = m_qpcFrequency.QuadPart / 10; 34 | } 35 | 36 | // Get elapsed time since the previous Update call. 37 | uint64 GetElapsedTicks() const { return m_elapsedTicks; } 38 | double GetElapsedSeconds() const { return TicksToSeconds(m_elapsedTicks); } 39 | 40 | // Get total time since the start of the program. 41 | uint64 GetTotalTicks() const { return m_totalTicks; } 42 | double GetTotalSeconds() const { return TicksToSeconds(m_totalTicks); } 43 | 44 | // Get total number of updates since start of the program. 45 | uint32 GetFrameCount() const { return m_frameCount; } 46 | 47 | // Get the current framerate. 48 | uint32 GetFramesPerSecond() const { return m_framesPerSecond; } 49 | 50 | // Set whether to use fixed or variable timestep mode. 51 | void SetFixedTimeStep(bool isFixedTimestep) { m_isFixedTimeStep = isFixedTimestep; } 52 | 53 | // Set how often to call Update when in fixed timestep mode. 54 | void SetTargetElapsedTicks(uint64 targetElapsed) { m_targetElapsedTicks = targetElapsed; } 55 | void SetTargetElapsedSeconds(double targetElapsed) { m_targetElapsedTicks = SecondsToTicks(targetElapsed); } 56 | 57 | // Integer format represents time using 10,000,000 ticks per second. 58 | static const uint64 TicksPerSecond = 10000000; 59 | 60 | static double TicksToSeconds(uint64 ticks) { return static_cast(ticks) / TicksPerSecond; } 61 | static uint64 SecondsToTicks(double seconds) { return static_cast(seconds * TicksPerSecond); } 62 | 63 | // After an intentional timing discontinuity (for instance a blocking IO operation) 64 | // call this to avoid having the fixed timestep logic attempt a set of catch-up 65 | // Update calls. 66 | 67 | void ResetElapsedTime() 68 | { 69 | if (!QueryPerformanceCounter(&m_qpcLastTime)) 70 | { 71 | throw ref new Platform::FailureException(); 72 | } 73 | 74 | m_leftOverTicks = 0; 75 | m_framesPerSecond = 0; 76 | m_framesThisSecond = 0; 77 | m_qpcSecondCounter = 0; 78 | } 79 | 80 | // Update timer state, calling the specified Update function the appropriate number of times. 81 | template 82 | void Tick(const TUpdate& update) 83 | { 84 | // Query the current time. 85 | LARGE_INTEGER currentTime; 86 | 87 | if (!QueryPerformanceCounter(¤tTime)) 88 | { 89 | throw ref new Platform::FailureException(); 90 | } 91 | 92 | uint64 timeDelta = currentTime.QuadPart - m_qpcLastTime.QuadPart; 93 | 94 | m_qpcLastTime = currentTime; 95 | m_qpcSecondCounter += timeDelta; 96 | 97 | // Clamp excessively large time deltas (e.g. after paused in the debugger). 98 | if (timeDelta > m_qpcMaxDelta) 99 | { 100 | timeDelta = m_qpcMaxDelta; 101 | } 102 | 103 | // Convert QPC units into a canonical tick format. This cannot overflow due to the previous clamp. 104 | timeDelta *= TicksPerSecond; 105 | timeDelta /= m_qpcFrequency.QuadPart; 106 | 107 | uint32 lastFrameCount = m_frameCount; 108 | 109 | if (m_isFixedTimeStep) 110 | { 111 | // Fixed timestep update logic 112 | 113 | // If the app is running very close to the target elapsed time (within 1/4 of a millisecond) just clamp 114 | // the clock to exactly match the target value. This prevents tiny and irrelevant errors 115 | // from accumulating over time. Without this clamping, a game that requested a 60 fps 116 | // fixed update, running with vsync enabled on a 59.94 NTSC display, would eventually 117 | // accumulate enough tiny errors that it would drop a frame. It is better to just round 118 | // small deviations down to zero to leave things running smoothly. 119 | 120 | if (abs(static_cast(timeDelta - m_targetElapsedTicks)) < TicksPerSecond / 4000) 121 | { 122 | timeDelta = m_targetElapsedTicks; 123 | } 124 | 125 | m_leftOverTicks += timeDelta; 126 | 127 | while (m_leftOverTicks >= m_targetElapsedTicks) 128 | { 129 | m_elapsedTicks = m_targetElapsedTicks; 130 | m_totalTicks += m_targetElapsedTicks; 131 | m_leftOverTicks -= m_targetElapsedTicks; 132 | m_frameCount++; 133 | 134 | update(); 135 | } 136 | } 137 | else 138 | { 139 | // Variable timestep update logic. 140 | m_elapsedTicks = timeDelta; 141 | m_totalTicks += timeDelta; 142 | m_leftOverTicks = 0; 143 | m_frameCount++; 144 | 145 | update(); 146 | } 147 | 148 | // Track the current framerate. 149 | if (m_frameCount != lastFrameCount) 150 | { 151 | m_framesThisSecond++; 152 | } 153 | 154 | if (m_qpcSecondCounter >= static_cast(m_qpcFrequency.QuadPart)) 155 | { 156 | m_framesPerSecond = m_framesThisSecond; 157 | m_framesThisSecond = 0; 158 | m_qpcSecondCounter %= m_qpcFrequency.QuadPart; 159 | } 160 | } 161 | 162 | private: 163 | // Source timing data uses QPC units. 164 | LARGE_INTEGER m_qpcFrequency; 165 | LARGE_INTEGER m_qpcLastTime; 166 | uint64 m_qpcMaxDelta; 167 | 168 | // Derived timing data uses a canonical tick format. 169 | uint64 m_elapsedTicks; 170 | uint64 m_totalTicks; 171 | uint64 m_leftOverTicks; 172 | 173 | // Members for tracking the framerate. 174 | uint32 m_frameCount; 175 | uint32 m_framesPerSecond; 176 | uint32 m_framesThisSecond; 177 | uint64 m_qpcSecondCounter; 178 | 179 | // Members for configuring fixed timestep mode. 180 | bool m_isFixedTimeStep; 181 | uint64 m_targetElapsedTicks; 182 | }; 183 | } 184 | -------------------------------------------------------------------------------- /ModelViewer/Common/ViewModelBase.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "ViewModelBase.h" 3 | 4 | using namespace Common; 5 | 6 | ViewModelBase::ViewModelBase() 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /ModelViewer/Common/ViewModelBase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Common\BindableBase.h" 4 | 5 | namespace Common 6 | { 7 | public ref class ViewModelBase : public BindableBase 8 | { 9 | internal: 10 | ViewModelBase(); 11 | }; 12 | } 13 | -------------------------------------------------------------------------------- /ModelViewer/Container.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "Container.h" 3 | 4 | -------------------------------------------------------------------------------- /ModelViewer/Container.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class Container 6 | { 7 | public: 8 | static Container& Instance() 9 | { 10 | static Container instance; 11 | return instance; 12 | } 13 | 14 | template 15 | T Create() 16 | { 17 | return injector.create(); 18 | } 19 | 20 | std::shared_ptr ResolveDirectXPageViewModelData() 21 | { 22 | if (_dxPageVMData == nullptr) 23 | _dxPageVMData = make_shared(); 24 | return _dxPageVMData; 25 | } 26 | 27 | private: 28 | Container() 29 | { 30 | } 31 | std::shared_ptr _dxPageVMData; 32 | }; 33 | 34 | 35 | -------------------------------------------------------------------------------- /ModelViewer/Content/Sample3DSceneRenderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "..\Common\DeviceResources.h" 4 | #include "ShaderStructures.h" 5 | #include "..\Common\StepTimer.h" 6 | #include "DXGrid.h" 7 | #include "Axis.h" 8 | #include "./Scene/GraphContainerNode.h" 9 | 10 | namespace ModelViewer 11 | { 12 | using namespace WinRTGLTFParser; 13 | using namespace Microsoft::WRL; 14 | using namespace Windows::System; 15 | using namespace Platform; 16 | using namespace Windows::Storage; 17 | using namespace DX; 18 | 19 | // This sample renderer instantiates a basic rendering pipeline. 20 | class Sample3DSceneRenderer 21 | { 22 | public: 23 | Sample3DSceneRenderer(const std::shared_ptr& deviceResources); 24 | 25 | class TexWrapper 26 | { 27 | public: 28 | ComPtr texResourceView; 29 | ComPtr texSampler; 30 | }; 31 | 32 | std::future CreateDeviceDependentResources(); 33 | void CreateWindowSizeDependentResources(); 34 | std::future CreateEnvironmentMapResourcesAsync(String^ envName); 35 | std::future CreateCubeMapAsync(ID3D11Device3 *device, StorageFolder^ imgFolder, String^ imgType, int mipLevel); 36 | std::future CreateBdrfLutAsync(StorageFolder^ imgFolder); 37 | void ReleaseDeviceDependentResources(); 38 | void Update(DX::StepTimer const& timer); 39 | void Render(); 40 | void StartTracking(float positionX, float positionY, VirtualKeyModifiers mod); 41 | void TrackingUpdate(float positionX, float positionY, VirtualKeyModifiers mod); 42 | void StopTracking(float positionX, float positionY, VirtualKeyModifiers mod); 43 | bool IsTracking() { return m_tracking; } 44 | void NotifyDataChanged(DirectXPageViewModelData const& data); 45 | 46 | private: 47 | void Rotate(float radians); 48 | 49 | private: 50 | class BufferWrapper 51 | { 52 | public: 53 | BufferWrapper(GLTF_BufferData^ data, ComPtr buffer) : 54 | _data(data), 55 | _buffer(buffer) 56 | { 57 | } 58 | BufferWrapper() {} 59 | ComPtr& Buffer() { return _buffer; } 60 | 61 | GLTF_BufferData^ Data() { return _data; } 62 | 63 | private: 64 | GLTF_BufferData^ _data; 65 | ComPtr _buffer; 66 | }; 67 | 68 | void DrawGrid(ID3D11DeviceContext2 *context); 69 | void DrawAxis(ID3D11DeviceContext2 *context, Axis *axis); 70 | 71 | // Cached pointer to device resources. 72 | std::shared_ptr m_deviceResources; 73 | 74 | // Direct3D resources for cube geometry. 75 | ComPtr m_inputLayout; 76 | ComPtr m_vertexBuffer; 77 | ComPtr m_indexBuffer; 78 | ComPtr m_vertexShader; 79 | ComPtr m_pixelShader; 80 | 81 | ComPtr _lineDrawingConstantBuffer; 82 | ComPtr _lineDrawingInputLayout; 83 | ComPtr _simpleVertexShader; 84 | ComPtr _simplePixelShader; 85 | 86 | ComPtr _envTexResourceView; 87 | ComPtr _envTexSampler; 88 | 89 | ComPtr _envSpecularTexResourceView; 90 | ComPtr _envSpecularTexSampler; 91 | 92 | ComPtr _brdfLutSampler; 93 | ComPtr _brdfLutResourceView; 94 | 95 | ComPtr _spSampler; 96 | ComPtr _spTexture; 97 | 98 | std::map _buffers; 99 | 100 | // System resources for cube geometry. 101 | //LineDrawingConstantBuffer _lineDrawingConstantBufferData; 102 | 103 | uint32 m_indexCount; 104 | 105 | // Variables used with the rendering loop. 106 | bool m_loadingComplete; 107 | float m_degreesPerSecond; 108 | bool m_tracking; 109 | 110 | float _lastPosX = 0.0f; 111 | float _lastPosY = 0.0f; 112 | 113 | float _yaw = -0.05f; 114 | float _pitch = -0.2f; 115 | float _roll = 0.0f; 116 | float _panx = 0.0f; 117 | float _pany = 0.0f; 118 | float _zoom = 5.0f; 119 | 120 | std::unique_ptr _grid; 121 | std::unique_ptr _mainAxes; 122 | 123 | ComPtr _pRasterState1; 124 | std::unique_ptr _context; 125 | }; 126 | } 127 | 128 | -------------------------------------------------------------------------------- /ModelViewer/Content/SampleFpsTextRenderer.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "SampleFpsTextRenderer.h" 3 | 4 | #include "Common/DirectXHelper.h" 5 | 6 | using namespace ModelViewer; 7 | using namespace Microsoft::WRL; 8 | 9 | // Initializes D2D resources used for text rendering. 10 | SampleFpsTextRenderer::SampleFpsTextRenderer(const std::shared_ptr& deviceResources) : 11 | m_text(L""), 12 | m_deviceResources(deviceResources) 13 | { 14 | ZeroMemory(&m_textMetrics, sizeof(DWRITE_TEXT_METRICS)); 15 | 16 | // Create device independent resources 17 | ComPtr textFormat; 18 | DX::ThrowIfFailed( 19 | m_deviceResources->GetDWriteFactory()->CreateTextFormat( 20 | L"Segoe UI", 21 | nullptr, 22 | DWRITE_FONT_WEIGHT_LIGHT, 23 | DWRITE_FONT_STYLE_NORMAL, 24 | DWRITE_FONT_STRETCH_NORMAL, 25 | 16.0f, 26 | L"en-US", 27 | &textFormat 28 | ) 29 | ); 30 | 31 | DX::ThrowIfFailed( 32 | textFormat.As(&m_textFormat) 33 | ); 34 | 35 | DX::ThrowIfFailed( 36 | m_textFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_NEAR) 37 | ); 38 | 39 | DX::ThrowIfFailed( 40 | m_deviceResources->GetD2DFactory()->CreateDrawingStateBlock(&m_stateBlock) 41 | ); 42 | 43 | CreateDeviceDependentResources(); 44 | } 45 | 46 | // Updates the text to be displayed. 47 | void SampleFpsTextRenderer::Update(DX::StepTimer const& timer) 48 | { 49 | // Update display text. 50 | uint32 fps = timer.GetFramesPerSecond(); 51 | 52 | m_text = (fps > 0) ? std::to_wstring(fps) + L" FPS" : L" - FPS"; 53 | 54 | ComPtr textLayout; 55 | DX::ThrowIfFailed( 56 | m_deviceResources->GetDWriteFactory()->CreateTextLayout( 57 | m_text.c_str(), 58 | (uint32) m_text.length(), 59 | m_textFormat.Get(), 60 | 240.0f, // Max width of the input text. 61 | 50.0f, // Max height of the input text. 62 | &textLayout 63 | ) 64 | ); 65 | 66 | DX::ThrowIfFailed( 67 | textLayout.As(&m_textLayout) 68 | ); 69 | 70 | DX::ThrowIfFailed( 71 | m_textLayout->GetMetrics(&m_textMetrics) 72 | ); 73 | } 74 | 75 | // Renders a frame to the screen. 76 | void SampleFpsTextRenderer::Render() 77 | { 78 | ID2D1DeviceContext* context = m_deviceResources->GetD2DDeviceContext(); 79 | Windows::Foundation::Size logicalSize = m_deviceResources->GetLogicalSize(); 80 | 81 | context->SaveDrawingState(m_stateBlock.Get()); 82 | context->BeginDraw(); 83 | 84 | // Position on the bottom right corner 85 | D2D1::Matrix3x2F screenTranslation = D2D1::Matrix3x2F::Translation( 86 | logicalSize.Width - m_textMetrics.layoutWidth, 87 | logicalSize.Height - m_textMetrics.height 88 | ); 89 | 90 | context->SetTransform(screenTranslation * m_deviceResources->GetOrientationTransform2D()); 91 | 92 | DX::ThrowIfFailed( 93 | m_textFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_TRAILING) 94 | ); 95 | 96 | context->DrawTextLayout( 97 | D2D1::Point2F(0.f, 0.f), 98 | m_textLayout.Get(), 99 | m_whiteBrush.Get() 100 | ); 101 | 102 | // Ignore D2DERR_RECREATE_TARGET here. This error indicates that the device 103 | // is lost. It will be handled during the next call to Present. 104 | HRESULT hr = context->EndDraw(); 105 | if (hr != D2DERR_RECREATE_TARGET) 106 | { 107 | DX::ThrowIfFailed(hr); 108 | } 109 | 110 | context->RestoreDrawingState(m_stateBlock.Get()); 111 | } 112 | 113 | void SampleFpsTextRenderer::CreateDeviceDependentResources() 114 | { 115 | DX::ThrowIfFailed( 116 | m_deviceResources->GetD2DDeviceContext()->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::White), &m_whiteBrush) 117 | ); 118 | } 119 | void SampleFpsTextRenderer::ReleaseDeviceDependentResources() 120 | { 121 | m_whiteBrush.Reset(); 122 | } -------------------------------------------------------------------------------- /ModelViewer/Content/SampleFpsTextRenderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "..\Common\DeviceResources.h" 5 | #include "..\Common\StepTimer.h" 6 | 7 | namespace ModelViewer 8 | { 9 | // Renders the current FPS value in the bottom right corner of the screen using Direct2D and DirectWrite. 10 | class SampleFpsTextRenderer 11 | { 12 | public: 13 | SampleFpsTextRenderer(const std::shared_ptr& deviceResources); 14 | void CreateDeviceDependentResources(); 15 | void ReleaseDeviceDependentResources(); 16 | void Update(DX::StepTimer const& timer); 17 | void Render(); 18 | 19 | private: 20 | // Cached pointer to device resources. 21 | std::shared_ptr m_deviceResources; 22 | 23 | // Resources related to text rendering. 24 | std::wstring m_text; 25 | DWRITE_TEXT_METRICS m_textMetrics; 26 | Microsoft::WRL::ComPtr m_whiteBrush; 27 | Microsoft::WRL::ComPtr m_stateBlock; 28 | Microsoft::WRL::ComPtr m_textLayout; 29 | Microsoft::WRL::ComPtr m_textFormat; 30 | }; 31 | } -------------------------------------------------------------------------------- /ModelViewer/Content/ShaderStructures.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define DIFFUSE 4 | 5 | namespace ModelViewer 6 | { 7 | using namespace DirectX; 8 | 9 | // Constant buffer used to send MVP matrices to the vertex shader. 10 | __declspec(align(16)) struct ModelViewProjectionConstantBuffer 11 | { 12 | XMFLOAT4X4 model; 13 | XMFLOAT4X4 view; 14 | XMFLOAT4X4 projection; 15 | 16 | #ifdef DIFFUSE 17 | XMFLOAT4 light_direction; 18 | XMFLOAT3 color; 19 | #endif 20 | 21 | }; 22 | 23 | __declspec(align(16)) struct LineDrawingConstantBuffer 24 | { 25 | XMFLOAT3 pos; 26 | XMFLOAT3 color; 27 | }; 28 | 29 | // Used to send per-vertex data to the vertex shader. 30 | struct VertexPositionColor 31 | { 32 | XMFLOAT3 pos; 33 | XMFLOAT3 color; 34 | }; 35 | 36 | struct Light 37 | { 38 | XMFLOAT3 dir; 39 | float padding1; 40 | XMFLOAT3 colour; 41 | float padding2; 42 | }; 43 | 44 | __declspec(align(16)) struct cbPerFrame 45 | { 46 | Light light; 47 | }; 48 | 49 | __declspec(align(16)) struct cbPerObject 50 | { 51 | float normalScale; 52 | XMFLOAT3 emissiveFactor; 53 | float occlusionStrength; 54 | XMFLOAT2 metallicRoughnessValues; 55 | float padding1; 56 | XMFLOAT4 baseColorFactor; 57 | XMFLOAT3 camera; 58 | float padding2; 59 | 60 | // debugging flags used for shader output of intermediate PBR variables 61 | XMFLOAT4 scaleDiffBaseMR; 62 | XMFLOAT4 scaleFGDSpec; 63 | XMFLOAT4 scaleIBLAmbient; 64 | }; 65 | } -------------------------------------------------------------------------------- /ModelViewer/Content/SimplePixelShader.hlsl: -------------------------------------------------------------------------------- 1 | // Per-pixel color data passed through the pixel shader. 2 | struct PixelShaderInput 3 | { 4 | float4 pos : SV_POSITION; 5 | float3 color : COLOR0; 6 | }; 7 | 8 | // A pass-through function for the (interpolated) color data. 9 | float4 main(PixelShaderInput input) : SV_TARGET 10 | { 11 | return float4(input.color, 1.0f); 12 | } 13 | -------------------------------------------------------------------------------- /ModelViewer/Content/SimpleVertexShader.hlsl: -------------------------------------------------------------------------------- 1 | // A constant buffer that stores the three basic column-major matrices for composing geometry. 2 | cbuffer ModelViewProjectionConstantBuffer : register(b0) 3 | { 4 | matrix model; 5 | matrix view; 6 | matrix projection; 7 | float4 light_direction; 8 | float3 color; 9 | }; 10 | 11 | // Per-vertex data used as input to the vertex shader. 12 | struct VertexShaderInput 13 | { 14 | float3 pos : POSITION; 15 | float3 color : COLOR0; 16 | }; 17 | 18 | // Per-pixel color data passed through the pixel shader. 19 | struct PixelShaderInput 20 | { 21 | float4 pos : SV_POSITION; 22 | float3 color : COLOR0; 23 | }; 24 | 25 | // Simple shader to do vertex processing on the GPU. 26 | PixelShaderInput main(VertexShaderInput input) 27 | { 28 | PixelShaderInput output; 29 | float4 pos = float4(input.pos, 1.0f); 30 | 31 | // Transform the vertex position into projected space. 32 | pos = mul(pos, model); 33 | pos = mul(pos, view); 34 | pos = mul(pos, projection); 35 | output.pos = pos; 36 | 37 | // Pass the color through without modification. 38 | output.color = color; 39 | 40 | return output; 41 | } 42 | -------------------------------------------------------------------------------- /ModelViewer/DXGrid.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "DXGrid.h" 3 | #include "Content\ShaderStructures.h" 4 | #include "Common\DirectXHelper.h" 5 | 6 | using namespace ModelViewer; 7 | using namespace DirectX; 8 | 9 | DXGrid::DXGrid() 10 | { 11 | } 12 | 13 | void DXGrid::Initialise(ID3D11Device *device) 14 | { 15 | int gridWidth = 10; 16 | float cellWidth = 1.0f; 17 | float cellHeight = 1.0f; 18 | 19 | unique_ptr vertices; 20 | unique_ptr indices; 21 | int index; 22 | D3D11_BUFFER_DESC vertexBufferDesc, indexBufferDesc; 23 | D3D11_SUBRESOURCE_DATA vertexData, indexData; 24 | 25 | int num = (gridWidth + 1) / 2; 26 | 27 | int numInRow = (num * 2 + 1)-1; 28 | 29 | // Calculate the number of vertices in the terrain mesh. 30 | m_vertexCount = numInRow * numInRow; 31 | 32 | // Set the index count to the same as the vertex count. 33 | m_indexCount = numInRow * 4; 34 | 35 | // Create the vertex array. 36 | vertices = make_unique(m_vertexCount); 37 | 38 | // Create the index array. 39 | indices = make_unique(m_indexCount); 40 | index = 0; 41 | 42 | for (int i = -num; i <= num; i++) 43 | { 44 | for (int j = -num; j <= num; j++) 45 | { 46 | if (i != 0 && j != 0) 47 | { 48 | vertices[index].pos = XMFLOAT3(cellWidth * i, 0.0f, cellHeight * j); 49 | vertices[index].color = XMFLOAT3(0.4f, 0.4f, 0.4f); 50 | index++; 51 | } 52 | } 53 | } 54 | 55 | index = 0; 56 | 57 | // first one direction... 58 | for (int k = 0; k < numInRow; k++) 59 | { 60 | indices[index] = k; 61 | index++; 62 | indices[index] = k + (numInRow * (numInRow - 1)); 63 | index++; 64 | } 65 | 66 | // then the other... 67 | for (int k = 0; k < numInRow * numInRow; k+=numInRow) 68 | { 69 | indices[index] = k; 70 | index++; 71 | indices[index] = k + numInRow - 1; 72 | index++; 73 | } 74 | 75 | // Set up the description of the static vertex buffer. 76 | vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT; 77 | vertexBufferDesc.ByteWidth = sizeof(VertexPositionColor) * m_vertexCount; 78 | vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; 79 | vertexBufferDesc.CPUAccessFlags = 0; 80 | vertexBufferDesc.MiscFlags = 0; 81 | vertexBufferDesc.StructureByteStride = 0; 82 | 83 | // Give the subresource structure a pointer to the vertex data. 84 | vertexData.pSysMem = vertices.get(); 85 | vertexData.SysMemPitch = 0; 86 | vertexData.SysMemSlicePitch = 0; 87 | 88 | // Now create the vertex buffer. 89 | DX::ThrowIfFailed(device->CreateBuffer(&vertexBufferDesc, &vertexData, m_vertexBuffer.GetAddressOf())); 90 | 91 | // Set up the description of the static index buffer. 92 | indexBufferDesc.Usage = D3D11_USAGE_DEFAULT; 93 | indexBufferDesc.ByteWidth = sizeof(unsigned long) * m_indexCount; 94 | indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER; 95 | indexBufferDesc.CPUAccessFlags = 0; 96 | indexBufferDesc.MiscFlags = 0; 97 | indexBufferDesc.StructureByteStride = 0; 98 | 99 | // Give the subresource structure a pointer to the index data. 100 | indexData.pSysMem = indices.get(); 101 | indexData.SysMemPitch = 0; 102 | indexData.SysMemSlicePitch = 0; 103 | 104 | // Create the index buffer. 105 | DX::ThrowIfFailed(device->CreateBuffer(&indexBufferDesc, &indexData, m_indexBuffer.GetAddressOf())); 106 | 107 | D3D11_RASTERIZER_DESC rasterizerState; 108 | rasterizerState.FillMode = D3D11_FILL_WIREFRAME; 109 | rasterizerState.CullMode = D3D11_CULL_NONE; 110 | rasterizerState.FrontCounterClockwise = true; 111 | rasterizerState.DepthBias = 1; 112 | rasterizerState.DepthBiasClamp = 0; 113 | rasterizerState.SlopeScaledDepthBias = -1.0; 114 | rasterizerState.DepthClipEnable = false; 115 | rasterizerState.ScissorEnable = false; 116 | rasterizerState.MultisampleEnable = false; 117 | rasterizerState.AntialiasedLineEnable = false; 118 | device->CreateRasterizerState(&rasterizerState, &_pRasterState); 119 | } 120 | 121 | void DXGrid::RenderBuffers(ID3D11DeviceContext* deviceContext) 122 | { 123 | unsigned int stride; 124 | unsigned int offset; 125 | 126 | // Set vertex buffer stride and offset. 127 | stride = sizeof(VertexPositionColor); 128 | offset = 0; 129 | 130 | auto vb = m_vertexBuffer.Get(); 131 | 132 | // Set the vertex buffer to active in the input assembler so it can be rendered. 133 | deviceContext->IASetVertexBuffers(0, 1, &vb, &stride, &offset); 134 | 135 | // Set the index buffer to active in the input assembler so it can be rendered. 136 | deviceContext->IASetIndexBuffer(m_indexBuffer.Get(), DXGI_FORMAT_R32_UINT, 0); 137 | 138 | //Set the render format to line list. 139 | // Set the type of primitive that should be rendered from this vertex buffer, in this case a line list. 140 | deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST); 141 | deviceContext->RSSetState(_pRasterState.Get()); 142 | } 143 | 144 | -------------------------------------------------------------------------------- /ModelViewer/DXGrid.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | using namespace Microsoft::WRL; 4 | 5 | class DXGrid 6 | { 7 | public: 8 | DXGrid(); 9 | void Initialise(ID3D11Device *device); 10 | void RenderBuffers(ID3D11DeviceContext* deviceContext); 11 | int IndexCount() { return m_indexCount; }; 12 | 13 | private: 14 | int m_vertexCount; 15 | int m_indexCount; 16 | ComPtr m_vertexBuffer, m_indexBuffer; 17 | ComPtr _pRasterState; 18 | }; 19 | 20 | -------------------------------------------------------------------------------- /ModelViewer/DXUtils.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "DXUtils.h" 3 | 4 | #include 5 | 6 | HRESULT DXUtils::CompileShader(_In_ LPCWSTR srcFile, const D3D_SHADER_MACRO *defines, _In_ LPCSTR entryPoint, _In_ LPCSTR profile, _Outptr_ ID3DBlob** blob) 7 | { 8 | if (!srcFile || !entryPoint || !profile || !blob) 9 | return E_INVALIDARG; 10 | 11 | *blob = nullptr; 12 | 13 | UINT flags = D3DCOMPILE_ENABLE_STRICTNESS; 14 | #if defined( DEBUG ) || defined( _DEBUG ) 15 | flags |= D3DCOMPILE_DEBUG; 16 | #endif 17 | 18 | ID3DBlob* shaderBlob = nullptr; 19 | ID3DBlob* errorBlob = nullptr; 20 | HRESULT hr = D3DCompileFromFile(srcFile, defines, D3D_COMPILE_STANDARD_FILE_INCLUDE, 21 | entryPoint, profile, 22 | flags, 0, &shaderBlob, &errorBlob); 23 | if (FAILED(hr)) 24 | { 25 | if (errorBlob) 26 | { 27 | OutputDebugStringA((char*)errorBlob->GetBufferPointer()); 28 | errorBlob->Release(); 29 | } 30 | 31 | if (shaderBlob) 32 | shaderBlob->Release(); 33 | 34 | return hr; 35 | } 36 | 37 | *blob = shaderBlob; 38 | 39 | return hr; 40 | } 41 | -------------------------------------------------------------------------------- /ModelViewer/DXUtils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class DXUtils 4 | { 5 | public: 6 | static HRESULT CompileShader(_In_ LPCWSTR srcFile, const D3D_SHADER_MACRO *defines, _In_ LPCSTR entryPoint, _In_ LPCSTR profile, _Outptr_ ID3DBlob** blob); 7 | }; 8 | 9 | -------------------------------------------------------------------------------- /ModelViewer/DecimalPlacesConverter.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "DecimalPlacesConverter.h" 3 | #include 4 | #include 5 | 6 | using namespace ModelViewer; 7 | using namespace Platform; 8 | using namespace Windows::UI::Xaml::Interop; 9 | 10 | DecimalPlacesConverter::DecimalPlacesConverter() 11 | { 12 | } 13 | 14 | Object ^ DecimalPlacesConverter::Convert(Object ^value, TypeName targetType, Object ^parameter, String ^language) 15 | { 16 | if (value != nullptr) 17 | { 18 | wchar_t number[256]; 19 | swprintf_s(number, 256, L"%.2f", (float)value); 20 | return ref new Platform::String(number); 21 | } 22 | return nullptr; 23 | } 24 | 25 | Object ^ DecimalPlacesConverter::ConvertBack(Object ^value, TypeName targetType, Object ^parameter, String ^language) 26 | { 27 | if (value != nullptr) 28 | { 29 | auto str = value->ToString(); 30 | auto ret = _wtof(str->Data()); 31 | return (float)ret; 32 | } 33 | return nullptr; 34 | } 35 | -------------------------------------------------------------------------------- /ModelViewer/DecimalPlacesConverter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | namespace ModelViewer 3 | { 4 | [Windows::UI::Xaml::Data::Bindable] 5 | [Windows::Foundation::Metadata::WebHostHidden] 6 | public ref class DecimalPlacesConverter sealed : Windows::UI::Xaml::Data::IValueConverter 7 | { 8 | public: 9 | DecimalPlacesConverter(); 10 | 11 | // Inherited via IValueConverter 12 | virtual Platform::Object ^ Convert(Platform::Object ^value, Windows::UI::Xaml::Interop::TypeName targetType, Platform::Object ^parameter, Platform::String ^language); 13 | virtual Platform::Object ^ ConvertBack(Platform::Object ^value, Windows::UI::Xaml::Interop::TypeName targetType, Platform::Object ^parameter, Platform::String ^language); 14 | 15 | property int DecimalPlaces 16 | { 17 | int get() { return _dps;; } 18 | void set(int value) { _dps = value; } 19 | } 20 | private: 21 | int _dps = 2; 22 | }; 23 | } 24 | -------------------------------------------------------------------------------- /ModelViewer/DelegateCommand.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "DelegateCommand.h" 3 | 4 | using namespace ModelViewer; 5 | 6 | DelegateCommand::DelegateCommand(ExecuteDelegate^ execute, CanExecuteDelegate^ canExecute) 7 | : executeDelegate(execute), canExecuteDelegate(canExecute) 8 | { 9 | } 10 | 11 | void DelegateCommand::Execute(Object^ parameter) 12 | { 13 | if (executeDelegate != nullptr) 14 | { 15 | executeDelegate(parameter); 16 | } 17 | } 18 | 19 | bool DelegateCommand::CanExecute(Object^ parameter) 20 | { 21 | if (canExecuteDelegate == nullptr) 22 | { 23 | return true; 24 | } 25 | 26 | bool canExecute = canExecuteDelegate(parameter); 27 | 28 | if (lastCanExecute != canExecute) 29 | { 30 | lastCanExecute = canExecute; 31 | CanExecuteChanged(this, nullptr); 32 | } 33 | 34 | return lastCanExecute; 35 | } -------------------------------------------------------------------------------- /ModelViewer/DelegateCommand.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace ModelViewer 4 | { 5 | using namespace Windows::UI::Xaml::Input; 6 | using namespace Windows::Foundation; 7 | using namespace Platform; 8 | 9 | public delegate void ExecuteDelegate(Object^ parameter); 10 | public delegate bool CanExecuteDelegate(Object^ parameter); 11 | 12 | public ref class DelegateCommand sealed : public ICommand 13 | { 14 | public: 15 | DelegateCommand(ExecuteDelegate^ execute, CanExecuteDelegate^ canExecute); 16 | 17 | virtual event EventHandler^ CanExecuteChanged; 18 | virtual void Execute(Object^ parameter); 19 | virtual bool CanExecute(Object^ parameter); 20 | 21 | private: 22 | ExecuteDelegate ^ executeDelegate; 23 | CanExecuteDelegate^ canExecuteDelegate; 24 | bool lastCanExecute; 25 | }; 26 | } 27 | -------------------------------------------------------------------------------- /ModelViewer/DirectXPage.xaml.h: -------------------------------------------------------------------------------- 1 | // 2 | // DirectXPage.xaml.h 3 | // Declaration of the DirectXPage class. 4 | // 5 | 6 | #pragma once 7 | 8 | #include "DirectXPage.g.h" 9 | 10 | #include "Common\DeviceResources.h" 11 | #include "ModelViewerMain.h" 12 | #include "SceneManager.h" 13 | 14 | namespace ModelViewer 15 | { 16 | using namespace Windows::UI::Xaml::Input; 17 | using namespace Windows::UI::Xaml::Controls; 18 | using namespace Windows::UI::Core; 19 | using namespace Platform; 20 | using namespace ViewModels; 21 | using namespace Windows::UI::ViewManagement; 22 | 23 | /// 24 | /// A page that hosts a DirectX SwapChainPanel. 25 | /// 26 | public ref class DirectXPage sealed 27 | { 28 | public: 29 | DirectXPage(); 30 | virtual ~DirectXPage(); 31 | 32 | void SaveInternalState(Windows::Foundation::Collections::IPropertySet^ state); 33 | void LoadInternalState(Windows::Foundation::Collections::IPropertySet^ state); 34 | 35 | property DirectXPageViewModel ^ ViewModel; 36 | 37 | private: 38 | class SceneUpdateProxy 39 | { 40 | public: 41 | SceneUpdateProxy(DirectXPage ^page) : 42 | owner(page) 43 | { 44 | SceneManager::Instance().RegisterForUpdates(bind(&SceneUpdateProxy::NotifySceneChanges, this, _1)); 45 | } 46 | 47 | void NotifySceneChanges(SceneManager const& scene) 48 | { 49 | owner->NotifySceneChanges(scene); 50 | } 51 | 52 | private: 53 | DirectXPage ^ owner; 54 | }; 55 | 56 | SceneUpdateProxy updates; 57 | UISettings^ _uiSettings; 58 | 59 | TreeViewNode^ CreateMeshNode(shared_ptr node); 60 | TreeViewNode^ CreateContainerNode(shared_ptr node); 61 | 62 | void NotifySceneChanges(SceneManager const& scene); 63 | 64 | TreeViewNode^ AddTreeItemsRecursive(shared_ptr node, TreeViewNode^ parent); 65 | 66 | // Window event handlers. 67 | void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args); 68 | 69 | // DisplayInformation event handlers. 70 | void OnDpiChanged(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args); 71 | void OnOrientationChanged(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args); 72 | void OnDisplayContentsInvalidated(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args); 73 | void OnThemeColorChanged(UISettings^ settings, Object^ sender); 74 | 75 | // Other event handlers. 76 | void AppBarButton_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); 77 | void OnCompositionScaleChanged(Windows::UI::Xaml::Controls::SwapChainPanel^ sender, Object^ args); 78 | void OnSwapChainPanelSizeChanged(Platform::Object^ sender, Windows::UI::Xaml::SizeChangedEventArgs^ e); 79 | 80 | // Track our independent input on a background worker thread. 81 | Windows::Foundation::IAsyncAction^ m_inputLoopWorker; 82 | Windows::UI::Core::CoreIndependentInputSource^ m_coreInput; 83 | 84 | // Independent input handling functions. 85 | void OnPointerPressed(Platform::Object^ sender, Windows::UI::Core::PointerEventArgs^ e); 86 | void OnPointerMoved(Platform::Object^ sender, Windows::UI::Core::PointerEventArgs^ e); 87 | void OnPointerReleased(Platform::Object^ sender, Windows::UI::Core::PointerEventArgs^ e); 88 | 89 | // Resources used to render the DirectX content in the XAML page background. 90 | std::shared_ptr m_deviceResources; 91 | std::unique_ptr m_main; 92 | bool m_windowVisible; 93 | bool m_controlPressed; 94 | void confirmColor_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); 95 | void cancelColor_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); 96 | void TreeView_ItemClick(Platform::Object^ sender, Windows::UI::Xaml::Controls::ItemClickEventArgs^ e); 97 | }; 98 | } 99 | 100 | -------------------------------------------------------------------------------- /ModelViewer/DirectXPageViewModelData.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "DirectXPageViewModelData.h" 3 | 4 | DirectXPageViewModelData::DirectXPageViewModelData() 5 | {} 6 | -------------------------------------------------------------------------------- /ModelViewer/DirectXPageViewModelData.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Subject.h" 4 | 5 | class DirectXPageViewModelData 6 | { 7 | public: 8 | DirectXPageViewModelData(); 9 | 10 | sub_token RegisterForUpdates(std::function slot) 11 | { 12 | return DataChanged.subscribe(slot); 13 | } 14 | 15 | void UnregisterForUpdates(sub_token conn) 16 | { 17 | conn.disconnect(); 18 | } 19 | 20 | const float *LightDirection() const { return _lightDirection; } 21 | void SetLightDirection(float ld[3]) 22 | { 23 | if (ld[0] == _lightDirection[0] && 24 | ld[0] == _lightDirection[1] && 25 | ld[0] == _lightDirection[2]) 26 | return; 27 | _lightDirection[0] = ld[0]; 28 | _lightDirection[1] = ld[1]; 29 | _lightDirection[2] = ld[2]; 30 | DataChanged.notify(*this); 31 | } 32 | 33 | float LightPitch() const { return _lightPitch; } 34 | void SetLightPitch(float lp) 35 | { 36 | if (lp == _lightPitch) 37 | return; 38 | _lightPitch = lp; 39 | DataChanged.notify(*this); 40 | } 41 | 42 | float LightRotation() const { return _lightRotation; } 43 | void SetLightRotation(float lr) 44 | { 45 | if (lr == _lightRotation) 46 | return; 47 | _lightRotation = lr; 48 | DataChanged.notify(*this); 49 | } 50 | 51 | float LightScale() const { return _lightScale; } 52 | void SetLightScale(float ls) 53 | { 54 | if (ls == _lightScale) 55 | return; 56 | _lightScale = ls; 57 | DataChanged.notify(*this); 58 | } 59 | 60 | float Ibl() const { return _ibl; } 61 | void SetIbl(float i) 62 | { 63 | if (i == _ibl) 64 | return; 65 | _ibl = i; 66 | DataChanged.notify(*this); 67 | } 68 | 69 | const unsigned char *LightColour() const { return _lightColour; } 70 | void SetLightColour(unsigned char lc[3]) 71 | { 72 | if (lc[0] == _lightColour[0] && 73 | lc[0] == _lightColour[1] && 74 | lc[0] == _lightColour[2]) 75 | return; 76 | _lightColour[0] = lc[0]; 77 | _lightColour[1] = lc[1]; 78 | _lightColour[2] = lc[2]; 79 | DataChanged.notify(*this); 80 | } 81 | 82 | bool Metallic() const { return _metallic; } 83 | void SetMetallic(bool m) 84 | { 85 | if (m == _metallic) 86 | return; 87 | _metallic = m; 88 | DataChanged.notify(*this); 89 | } 90 | 91 | bool Roughness() const { return _roughness; } 92 | void SetRoughness(bool r) 93 | { 94 | if (r == _roughness) 95 | return; 96 | _roughness = r; 97 | DataChanged.notify(*this); 98 | } 99 | 100 | bool BaseColour() const { return _baseColour; } 101 | void SetBaseColour(bool bc) 102 | { 103 | if (bc == _baseColour) 104 | return; 105 | _baseColour = bc; 106 | DataChanged.notify(*this); 107 | } 108 | 109 | bool Diffuse() const { return _diffuse; } 110 | void SetDiffuse(bool d) 111 | { 112 | if (d == _diffuse) 113 | return; 114 | _diffuse = d; 115 | DataChanged.notify(*this); 116 | } 117 | 118 | bool Specular() const { return _specular; } 119 | void SetSpecular(bool s) 120 | { 121 | if (s == _specular) 122 | return; 123 | _specular = s; 124 | DataChanged.notify(*this); 125 | } 126 | 127 | bool F() const { return _f; } 128 | void SetF(bool f) 129 | { 130 | if (f == _f) 131 | return; 132 | _f = f; 133 | DataChanged.notify(*this); 134 | } 135 | 136 | bool G() const { return _g; } 137 | void SetG(bool g) 138 | { 139 | if (g == _g) 140 | return; 141 | _g = g; 142 | DataChanged.notify(*this); 143 | } 144 | 145 | bool D()const { return _d; } 146 | void SetD(bool d) 147 | { 148 | if (d == _d) 149 | return; 150 | _d = d; 151 | DataChanged.notify(*this); 152 | } 153 | 154 | private: 155 | float _lightDirection[3] = { 0.5f, 0.5f, 0.0f }; 156 | 157 | float _lightPitch = 0.0f; 158 | float _lightRotation = 0.0f; 159 | float _lightScale = 0.0f; 160 | float _ibl = 1.0f; 161 | unsigned char _lightColour[3] = {255, 255, 255}; 162 | 163 | bool _metallic = false; 164 | bool _roughness = false; 165 | bool _baseColour = false; 166 | bool _diffuse = false; 167 | bool _specular = false; 168 | bool _f = false; 169 | bool _g = false; 170 | bool _d = false; 171 | 172 | subject DataChanged; 173 | }; 174 | 175 | 176 | -------------------------------------------------------------------------------- /ModelViewer/EventShim.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | using namespace WinRTGLTFParser; 6 | using namespace Platform; 7 | 8 | ref class EventShim sealed 9 | { 10 | internal: 11 | EventShim(std::function bcallback, 12 | std::function mcallback, 13 | std::function tcallback, 14 | std::function tmcallback, 15 | std::function sncallback) : 16 | bufferCallback(move(bcallback)), 17 | materialCallback(move(mcallback)), 18 | textureCallback(move(tcallback)), 19 | transformCallback(move(tmcallback)), 20 | sceneNodeCallback(move(sncallback)) 21 | { 22 | 23 | } 24 | 25 | public: 26 | void OnBuffer(Object^ sender, GLTF_BufferData^ data) 27 | { 28 | bufferCallback(data); 29 | } 30 | void OnTexture(Object^ sender, GLTF_TextureData^ data) 31 | { 32 | textureCallback(data); 33 | } 34 | void OnMaterial(Object^ sender, GLTF_MaterialData^ data) 35 | { 36 | materialCallback(data); 37 | } 38 | void OnTransform(Object^ sender, GLTF_TransformData^ data) 39 | { 40 | transformCallback(data); 41 | } 42 | void OnSceneNode(Object^ sender, GLTF_SceneNodeData^ data) 43 | { 44 | sceneNodeCallback(data); 45 | } 46 | 47 | private: 48 | std::function bufferCallback; 49 | std::function textureCallback; 50 | std::function materialCallback; 51 | std::function transformCallback; 52 | std::function sceneNodeCallback; 53 | }; -------------------------------------------------------------------------------- /ModelViewer/FileSystemData.h: -------------------------------------------------------------------------------- 1 | //********************************************************* 2 | // 3 | // Copyright (c) Microsoft. All rights reserved. 4 | // This code is licensed under the MIT License (MIT). 5 | // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF 6 | // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY 7 | // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR 8 | // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. 9 | // 10 | //********************************************************* 11 | #pragma once 12 | #include 13 | #include "SceneManager.h" 14 | 15 | namespace ModelViewer 16 | { 17 | using namespace std; 18 | 19 | [Windows::UI::Xaml::Data::Bindable] 20 | [Windows::Foundation::Metadata::WebHostHidden] 21 | public ref class GraphNodeData sealed 22 | { 23 | internal: 24 | GraphNodeData(shared_ptr node) : 25 | _node(node) 26 | { 27 | this->Name = ref new String(node->Name().c_str()); 28 | } 29 | 30 | public: 31 | 32 | property Platform::String^ Name 33 | { 34 | Platform::String^ get() { return name; } 35 | void set(Platform::String^ value) { name = value; } 36 | } 37 | 38 | property bool IsFolder 39 | { 40 | bool get() { return isFolder; } 41 | void set(bool value) { isFolder = value; } 42 | } 43 | 44 | property bool IsSelected 45 | { 46 | bool get() { return _node->IsSelected(); } 47 | void set(bool value) 48 | { 49 | SceneManager::Instance().SetSelected(_node); 50 | } 51 | } 52 | 53 | private: 54 | Platform::String^ name = nullptr; 55 | bool isFolder = false; 56 | shared_ptr _node; 57 | }; 58 | } 59 | 60 | -------------------------------------------------------------------------------- /ModelViewer/GlyphConverter.cpp: -------------------------------------------------------------------------------- 1 | //********************************************************* 2 | // 3 | // Copyright (c) Microsoft. All rights reserved. 4 | // This code is licensed under the MIT License (MIT). 5 | // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF 6 | // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY 7 | // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR 8 | // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. 9 | // 10 | //********************************************************* 11 | #include "pch.h" 12 | #include "GlyphConverter.h" 13 | 14 | using namespace ModelViewer; 15 | 16 | using namespace Platform; 17 | using namespace Windows::UI::Xaml; 18 | using namespace Windows::UI::Xaml::Interop; 19 | 20 | GlyphConverter::GlyphConverter() 21 | { 22 | } 23 | 24 | Object ^ GlyphConverter::Convert(Object ^value, TypeName targetType, Object ^parameter, String ^language) 25 | { 26 | IBox^ isExpanded = dynamic_cast^>(value); 27 | if (isExpanded != nullptr && isExpanded->Value) 28 | { 29 | return ExpandedGlyph; 30 | } 31 | else 32 | { 33 | return CollapsedGlyph; 34 | } 35 | } 36 | 37 | Object ^ GlyphConverter::ConvertBack(Object ^value, TypeName targetType, Object ^parameter, String ^language) 38 | { 39 | throw ref new NotImplementedException(); 40 | } 41 | -------------------------------------------------------------------------------- /ModelViewer/GlyphConverter.h: -------------------------------------------------------------------------------- 1 | //********************************************************* 2 | // 3 | // Copyright (c) Microsoft. All rights reserved. 4 | // This code is licensed under the MIT License (MIT). 5 | // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF 6 | // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY 7 | // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR 8 | // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. 9 | // 10 | //********************************************************* 11 | #pragma once 12 | namespace ModelViewer 13 | { 14 | [Windows::UI::Xaml::Data::Bindable] 15 | [Windows::Foundation::Metadata::WebHostHidden] 16 | public ref class GlyphConverter sealed : Windows::UI::Xaml::Data::IValueConverter 17 | { 18 | public: 19 | GlyphConverter(); 20 | 21 | // Inherited via IValueConverter 22 | virtual Platform::Object ^ Convert(Platform::Object ^value, Windows::UI::Xaml::Interop::TypeName targetType, Platform::Object ^parameter, Platform::String ^language); 23 | virtual Platform::Object ^ ConvertBack(Platform::Object ^value, Windows::UI::Xaml::Interop::TypeName targetType, Platform::Object ^parameter, Platform::String ^language); 24 | 25 | property Platform::String^ ExpandedGlyph 26 | { 27 | Platform::String^ get() { return expandedGlyph; } 28 | void set(Platform::String^ value) { expandedGlyph = value; } 29 | } 30 | 31 | property Platform::String^ CollapsedGlyph 32 | { 33 | Platform::String^ get() { return collapsedGlyph; } 34 | void set(Platform::String^ value) { collapsedGlyph = value; } 35 | } 36 | private: 37 | Platform::String^ expandedGlyph = nullptr; 38 | Platform::String^ collapsedGlyph = nullptr; 39 | }; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /ModelViewer/ImgUtils.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "ImgUtils.h" 3 | #include "Common\DirectXHelper.h" 4 | 5 | using namespace DX; 6 | 7 | vector ImgUtils::LoadRGBAImage(void *imgFileData, size_t imgFileDataSize, uint32_t& width, uint32_t& height, 8 | bool jpg, const wchar_t *filename) 9 | { 10 | ComPtr wicFactory; 11 | ThrowIfFailed(CoCreateInstance(CLSID_WICImagingFactory2, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&wicFactory))); 12 | 13 | IWICStream *pIWICStream; 14 | // Create a WIC stream to map onto the memory. 15 | ThrowIfFailed(wicFactory->CreateStream(&pIWICStream)); 16 | 17 | // Initialize the stream with the memory pointer and size. 18 | ThrowIfFailed(pIWICStream->InitializeFromMemory(reinterpret_cast(imgFileData), static_cast(imgFileDataSize))); 19 | 20 | ComPtr decoder; 21 | if (jpg) 22 | { 23 | ThrowIfFailed(wicFactory->CreateDecoderFromFilename(filename, nullptr, GENERIC_READ, WICDecodeMetadataCacheOnDemand, decoder.GetAddressOf())); 24 | //ThrowIfFailed(wicFactory->CreateDecoder(GUID_ContainerFormatJpeg, nullptr, decoder.GetAddressOf())); 25 | //decoder->Initialize(pIWICStream, WICDecodeMetadataCacheOnLoad); 26 | } 27 | else 28 | { 29 | ThrowIfFailed(wicFactory->CreateDecoderFromStream(pIWICStream, nullptr, WICDecodeMetadataCacheOnLoad, decoder.GetAddressOf())); 30 | } 31 | 32 | ComPtr frame; 33 | ThrowIfFailed(decoder->GetFrame(0, frame.GetAddressOf())); 34 | 35 | ThrowIfFailed(frame->GetSize(&width, &height)); 36 | 37 | WICPixelFormatGUID pixelFormat; 38 | ThrowIfFailed(frame->GetPixelFormat(&pixelFormat)); 39 | 40 | uint32_t rowPitch = width * sizeof(uint32_t); 41 | uint32_t imageSize = rowPitch * height; 42 | 43 | vector image; 44 | image.resize(size_t(imageSize)); 45 | 46 | if (memcmp(&pixelFormat, &GUID_WICPixelFormat32bppRGBA, sizeof(GUID)) == 0) 47 | { 48 | ThrowIfFailed(frame->CopyPixels(0, rowPitch, imageSize, reinterpret_cast(image.data()))); 49 | } 50 | else 51 | { 52 | ComPtr formatConverter; 53 | ThrowIfFailed(wicFactory->CreateFormatConverter(formatConverter.GetAddressOf())); 54 | 55 | BOOL canConvert = FALSE; 56 | ThrowIfFailed(formatConverter->CanConvert(pixelFormat, GUID_WICPixelFormat32bppRGBA, &canConvert)); 57 | if (!canConvert) 58 | { 59 | throw exception("CanConvert"); 60 | } 61 | 62 | ThrowIfFailed(formatConverter->Initialize(frame.Get(), GUID_WICPixelFormat32bppRGBA, 63 | WICBitmapDitherTypeErrorDiffusion, nullptr, 0, WICBitmapPaletteTypeMedianCut)); 64 | 65 | ThrowIfFailed(formatConverter->CopyPixels(0, rowPitch, imageSize, reinterpret_cast(image.data()))); 66 | } 67 | 68 | return image; 69 | } 70 | -------------------------------------------------------------------------------- /ModelViewer/ImgUtils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | using namespace std; 5 | using namespace Microsoft::WRL; 6 | 7 | class ImgUtils 8 | { 9 | public: 10 | static vector LoadRGBAImage(void *imgFileData, size_t imgFileDataSize, uint32_t& width, uint32_t& height, 11 | bool jpg = false, const wchar_t *filename = nullptr); 12 | }; 13 | 14 | -------------------------------------------------------------------------------- /ModelViewer/ModelBufferManager.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "ModelBufferManager.h" 3 | 4 | ModelBufferManager::ModelBufferManager() 5 | { 6 | } 7 | -------------------------------------------------------------------------------- /ModelViewer/ModelBufferManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "BufferCache.h" 3 | 4 | class ModelBufferManager : public Singleton 5 | { 6 | friend class Singleton; 7 | 8 | public: 9 | BufferCache *CurrentBufferCache() 10 | { 11 | if (_currBufferCache == nullptr) 12 | { 13 | _currBufferCache = make_unique>(); 14 | } 15 | return _currBufferCache.get(); 16 | } 17 | 18 | protected: 19 | ModelBufferManager(); 20 | 21 | private: 22 | unique_ptr> _currBufferCache = nullptr; 23 | }; 24 | 25 | -------------------------------------------------------------------------------- /ModelViewer/ModelFactory.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "ModelFactory.h" 3 | #include "EventShim.h" 4 | #include "SceneManager.h" 5 | 6 | using namespace std; 7 | 8 | ModelFactory::ModelFactory() 9 | { 10 | } 11 | 12 | void ModelFactory::CreateBuffer(GLTF_BufferData^ data) 13 | { 14 | auto node = dynamic_cast(_currentNode); 15 | if (node) 16 | { 17 | node->CreateBuffer(data); 18 | } 19 | } 20 | void ModelFactory::CreateTexture(GLTF_TextureData^ data) 21 | { 22 | auto node = dynamic_cast(_currentNode); 23 | if (node) 24 | { 25 | node->CreateTexture(data); 26 | } 27 | } 28 | void ModelFactory::CreateMaterial(GLTF_MaterialData^ data) 29 | { 30 | auto node = dynamic_cast(_currentNode); 31 | if (node) 32 | { 33 | node->CreateMaterial(data); 34 | } 35 | } 36 | void ModelFactory::CreateTransform(GLTF_TransformData^ data) 37 | { 38 | auto node = dynamic_cast(_currentNode); 39 | if (node) 40 | { 41 | node->CreateTransform(data); 42 | } 43 | } 44 | 45 | GraphNode * ModelFactory::InitialiseMesh(GLTF_SceneNodeData^ data) 46 | { 47 | auto mesh = new MeshNode(data->NodeIndex); 48 | _currentNode = mesh; 49 | 50 | auto devResources = SceneManager::Instance().DevResources(); 51 | mesh->Initialise(devResources); 52 | 53 | return mesh; 54 | } 55 | 56 | void ModelFactory::CreateSceneNode(GLTF_SceneNodeData^ data) 57 | { 58 | GraphNode *parent = nullptr; 59 | if (_root && data->ParentIndex != -1) 60 | { 61 | parent = _root->FindChildByIndex(data->ParentIndex); 62 | } 63 | 64 | if (data->IsMesh) 65 | { 66 | _currentNode = InitialiseMesh(data); 67 | } 68 | else 69 | { 70 | _currentNode = new GraphContainerNode(data->NodeIndex); 71 | auto devResources = SceneManager::Instance().DevResources(); 72 | _currentNode->Initialise(devResources); 73 | } 74 | _currentNode->SetName(data->Name->Data()); 75 | 76 | if (_root == nullptr) 77 | { 78 | _root = _currentNode; 79 | } 80 | else if (parent && _currentNode) 81 | { 82 | shared_ptr sp; 83 | sp.reset(_currentNode); 84 | parent->AddChild(sp); 85 | } 86 | } 87 | 88 | future> ModelFactory::CreateFromFileAsync(StorageFile^ file) 89 | { 90 | _parser = ref new GLTF_Parser(); 91 | _root = _currentNode = nullptr; 92 | 93 | function snmmemfun = bind(&ModelFactory::CreateSceneNode, &(ModelFactory::Instance()), placeholders::_1); 94 | function memfun = bind(&ModelFactory::CreateBuffer, &(ModelFactory::Instance()), placeholders::_1); 95 | function tmemfun = bind(&ModelFactory::CreateTexture, &(ModelFactory::Instance()), placeholders::_1); 96 | function mmemfun = bind(&ModelFactory::CreateMaterial, &(ModelFactory::Instance()), placeholders::_1); 97 | function tmmemfun = bind(&ModelFactory::CreateTransform, &(ModelFactory::Instance()), placeholders::_1); 98 | 99 | auto es = ref new EventShim(memfun, mmemfun, tmemfun, tmmemfun, snmmemfun); 100 | 101 | _parser->OnBufferEvent += ref new BufferEventHandler(es, &EventShim::OnBuffer); 102 | _parser->OnTextureEvent += ref new TextureEventHandler(es, &EventShim::OnTexture); 103 | _parser->OnMaterialEvent += ref new MaterialEventHandler(es, &EventShim::OnMaterial); 104 | _parser->OnTransformEvent += ref new TransformEventHandler(es, &EventShim::OnTransform); 105 | _parser->OnSceneNodeEvent += ref new SceneNodeEventHandler(es, &EventShim::OnSceneNode); 106 | 107 | co_await async([this, file]() { _parser->ParseFile(file); }); 108 | 109 | _root->AfterLoad(); 110 | 111 | // call afterLoad on all children... 112 | _root->ForAllChildrenRecursive([](GraphNode& node) 113 | { 114 | node.AfterLoad(); 115 | }); 116 | 117 | shared_ptr sp; 118 | sp.reset(_root); 119 | co_return sp; 120 | } -------------------------------------------------------------------------------- /ModelViewer/ModelFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Scene\GraphNode.h" 3 | #include "Scene\MeshNode.h" 4 | #include "ppltasks.h" 5 | #include 6 | #include 7 | #include "Singleton.h" 8 | 9 | using namespace Windows::Foundation; 10 | using namespace ModelViewer; 11 | using namespace std; 12 | using namespace Platform; 13 | using namespace concurrency; 14 | using namespace WinRTGLTFParser; 15 | using namespace Windows::Storage; 16 | 17 | class ModelFactory : public Singleton 18 | { 19 | friend class Singleton; 20 | 21 | public: 22 | future> CreateFromFileAsync(StorageFile^ file); 23 | void CreateSceneNode(GLTF_SceneNodeData^ data); 24 | GraphNode *InitialiseMesh(GLTF_SceneNodeData^ data); 25 | void CreateBuffer(GLTF_BufferData^ data); 26 | void CreateTexture(GLTF_TextureData^ data); 27 | void CreateMaterial(GLTF_MaterialData^ data); 28 | void CreateTransform(GLTF_TransformData^ data); 29 | 30 | protected: 31 | ModelFactory(); 32 | 33 | private: 34 | GLTF_Parser^ _parser; 35 | GraphNode *_root; 36 | GraphNode *_currentNode; 37 | }; 38 | 39 | -------------------------------------------------------------------------------- /ModelViewer/ModelViewerMain.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "ModelViewerMain.h" 3 | #include "Common\DirectXHelper.h" 4 | 5 | using namespace ModelViewer; 6 | using namespace Windows::Foundation; 7 | using namespace Windows::System::Threading; 8 | using namespace Concurrency; 9 | 10 | // Loads and initializes application assets when the application is loaded. 11 | ModelViewerMain::ModelViewerMain(const shared_ptr& deviceResources) : 12 | m_deviceResources(deviceResources), m_pointerLocationX(0.0f), m_renderTexture(make_unique(deviceResources)) 13 | { 14 | // Register to be notified if the Device is lost or recreated 15 | m_deviceResources->RegisterDeviceNotify(this); 16 | 17 | // TODO: Replace this with your app's content initialization. 18 | m_fpsTextRenderer = unique_ptr(new SampleFpsTextRenderer(m_deviceResources)); 19 | m_sceneRenderer = unique_ptr(new Sample3DSceneRenderer(m_deviceResources)); 20 | 21 | // TODO: Change the timer settings if you want something other than the default variable timestep mode. 22 | // e.g. for 60 FPS fixed timestep update logic, call: 23 | /* 24 | m_timer.SetFixedTimeStep(true); 25 | m_timer.SetTargetElapsedSeconds(1.0 / 60); 26 | */ 27 | } 28 | 29 | ModelViewerMain::~ModelViewerMain() 30 | { 31 | // Deregister device notification 32 | m_deviceResources->RegisterDeviceNotify(nullptr); 33 | } 34 | 35 | // Updates application state when the window size changes (e.g. device orientation change) 36 | void ModelViewerMain::CreateWindowSizeDependentResources() 37 | { 38 | // TODO: Replace this with the size-dependent initialization of your app's content. 39 | m_sceneRenderer->CreateWindowSizeDependentResources(); 40 | } 41 | 42 | void ModelViewerMain::StartRenderLoop() 43 | { 44 | // If the animation render loop is already running then do not start another thread. 45 | if (m_renderLoopWorker != nullptr && m_renderLoopWorker->Status == AsyncStatus::Started) 46 | { 47 | return; 48 | } 49 | 50 | // Create a task that will be run on a background thread. 51 | auto workItemHandler = ref new WorkItemHandler([this](IAsyncAction ^ action) 52 | { 53 | // Calculate the updated frame and render once per vertical blanking interval. 54 | while (action->Status == AsyncStatus::Started) 55 | { 56 | critical_section::scoped_lock lock(m_criticalSection); 57 | Update(); 58 | if (Render()) 59 | { 60 | m_deviceResources->Present(); 61 | } 62 | } 63 | }); 64 | 65 | // Run task on a dedicated high priority background thread. 66 | m_renderLoopWorker = ThreadPool::RunAsync(workItemHandler, WorkItemPriority::High, WorkItemOptions::TimeSliced); 67 | } 68 | 69 | void ModelViewerMain::StopRenderLoop() 70 | { 71 | m_renderLoopWorker->Cancel(); 72 | } 73 | 74 | // Updates the application state once per frame. 75 | void ModelViewerMain::Update() 76 | { 77 | ProcessInput(); 78 | 79 | // Update scene objects. 80 | m_timer.Tick([&]() 81 | { 82 | // TODO: Replace this with your app's content update functions. 83 | m_sceneRenderer->Update(m_timer); 84 | m_fpsTextRenderer->Update(m_timer); 85 | }); 86 | } 87 | 88 | // Process all input from the user before updating game state 89 | void ModelViewerMain::ProcessInput() 90 | { 91 | // TODO: Add per frame input handling here. 92 | //m_sceneRenderer->TrackingUpdate(m_pointerLocationX, m_pointerLocationY, m_mod); 93 | } 94 | 95 | // Renders the current frame according to the current application state. 96 | // Returns true if the frame was rendered and is ready to be displayed. 97 | bool ModelViewerMain::Render() 98 | { 99 | // Don't try to render anything before the first Update. 100 | if (m_timer.GetFrameCount() == 0) 101 | { 102 | return false; 103 | } 104 | 105 | auto context = m_deviceResources->GetD3DDeviceContext(); 106 | 107 | // Reset the viewport to target the whole screen. 108 | auto viewport = m_deviceResources->GetScreenViewport(); 109 | context->RSSetViewports(1, &viewport); 110 | 111 | // Reset render targets to the screen. 112 | ID3D11RenderTargetView *const targets[1] = { m_deviceResources->GetBackBufferRenderTargetView() }; 113 | context->OMSetRenderTargets(1, targets, m_deviceResources->GetDepthStencilView()); 114 | 115 | // Clear the back buffer and depth stencil view. 116 | XMVECTORF32 color; 117 | color.v = XMColorSRGBToRGB(XMLoadFloat4(&_backgroundColour)/*DirectX::Colors::CornflowerBlue*/); 118 | context->ClearRenderTargetView(m_deviceResources->GetBackBufferRenderTargetView(), color); 119 | context->ClearDepthStencilView(m_deviceResources->GetDepthStencilView(), D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0); 120 | 121 | // Render the scene objects. 122 | // TODO: Replace this with your app's content rendering functions. 123 | m_sceneRenderer->Render(); 124 | m_fpsTextRenderer->Render(); 125 | 126 | return true; 127 | } 128 | 129 | // Notifies renderers that device resources need to be released. 130 | void ModelViewerMain::OnDeviceLost() 131 | { 132 | m_sceneRenderer->ReleaseDeviceDependentResources(); 133 | m_fpsTextRenderer->ReleaseDeviceDependentResources(); 134 | } 135 | 136 | // Notifies renderers that device resources may now be recreated. 137 | void ModelViewerMain::OnDeviceRestored() 138 | { 139 | m_sceneRenderer->CreateDeviceDependentResources(); 140 | m_fpsTextRenderer->CreateDeviceDependentResources(); 141 | CreateWindowSizeDependentResources(); 142 | } 143 | -------------------------------------------------------------------------------- /ModelViewer/ModelViewerMain.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Common\StepTimer.h" 4 | #include "Common\DeviceResources.h" 5 | #include "Content\Sample3DSceneRenderer.h" 6 | #include "Content\SampleFpsTextRenderer.h" 7 | #include 8 | 9 | // Renders Direct2D and 3D content on the screen. 10 | namespace ModelViewer 11 | { 12 | using namespace std; 13 | using namespace DX; 14 | using namespace Concurrency; 15 | using namespace Windows::Foundation; 16 | 17 | class ModelViewerMain : public IDeviceNotify 18 | { 19 | public: 20 | ModelViewerMain(const shared_ptr& deviceResources); 21 | ~ModelViewerMain(); 22 | void CreateWindowSizeDependentResources(); 23 | void StartTracking(float positionX, float positionY, VirtualKeyModifiers mod) 24 | { 25 | m_sceneRenderer->StartTracking(positionX, positionY, mod); 26 | } 27 | void TrackingUpdate(float positionX, float positionY, VirtualKeyModifiers mod) 28 | { 29 | m_sceneRenderer->TrackingUpdate(positionX, positionY, mod); 30 | } 31 | void StopTracking(float positionX, float positionY, VirtualKeyModifiers mod) 32 | { 33 | m_sceneRenderer->StopTracking(positionX, positionY, mod); 34 | } 35 | bool IsTracking() { return m_sceneRenderer->IsTracking(); } 36 | void StartRenderLoop(); 37 | void StopRenderLoop(); 38 | critical_section& GetCriticalSection() { return m_criticalSection; } 39 | 40 | // IDeviceNotify 41 | virtual void OnDeviceLost(); 42 | virtual void OnDeviceRestored(); 43 | 44 | void SetBackgroundColour(XMVECTORF32 colour) { XMStoreFloat4(&_backgroundColour, colour); } 45 | 46 | private: 47 | void ProcessInput(); 48 | void Update(); 49 | bool Render(); 50 | 51 | // Cached pointer to device resources. 52 | shared_ptr m_deviceResources; 53 | 54 | // TODO: Replace with your own content renderers. 55 | unique_ptr m_sceneRenderer; 56 | unique_ptr m_fpsTextRenderer; 57 | 58 | unique_ptr m_renderTexture; 59 | 60 | IAsyncAction^ m_renderLoopWorker; 61 | critical_section m_criticalSection; 62 | 63 | // Rendering loop timer. 64 | StepTimer m_timer; 65 | 66 | // Track current input pointer position. 67 | float m_pointerLocationX; 68 | float m_pointerLocationY; 69 | VirtualKeyModifiers m_mod; 70 | 71 | XMFLOAT4 _backgroundColour; 72 | }; 73 | } -------------------------------------------------------------------------------- /ModelViewer/NodeMaterial.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "NodeMaterial.h" 3 | 4 | NodeMaterial::NodeMaterial() 5 | { 6 | } 7 | 8 | NodeMaterial::~NodeMaterial() 9 | { 10 | } 11 | 12 | void NodeMaterial::Initialise(GLTF_MaterialData^ data) 13 | { 14 | _name = data->MaterialName->Data(); 15 | _Emissivetexture = data->Emissivetexture; 16 | _Normaltexture = data->Normaltexture; 17 | _Occlusiontexture = data->Occlusiontexture; 18 | _Pbrmetallicroughness_Basecolortexture = data->Pbrmetallicroughness_Basecolortexture; 19 | _Pbrmetallicroughness_Metallicroughnesstexture = data->Pbrmetallicroughness_Metallicroughnesstexture; 20 | _emmissiveFactor.x = data->emmissiveFactor[0]; 21 | _emmissiveFactor.y = data->emmissiveFactor[1]; 22 | _emmissiveFactor.z = data->emmissiveFactor[2]; 23 | _baseColorFactor.x = data->baseColourFactor[0]; 24 | _baseColorFactor.y = data->baseColourFactor[1]; 25 | _baseColorFactor.z = data->baseColourFactor[2]; 26 | _baseColorFactor.w = data->baseColourFactor[3]; 27 | _metallicFactor = data->metallicFactor; 28 | _roughnessFactor = data->roughnessFactor; 29 | } 30 | 31 | shared_ptr NodeMaterial::HasTextureId(unsigned int idx) 32 | { 33 | auto res = std::find_if(_textures.begin(), _textures.end(), [idx](pair> tex) 34 | { 35 | return tex.second->GetIndex() == idx ? true : false; 36 | }); 37 | return res != _textures.end() ? (*res).second : nullptr; 38 | } 39 | 40 | void NodeMaterial::AddTexture(shared_ptr tex) 41 | { 42 | _textures[tex->Type()] = tex; 43 | } 44 | 45 | void NodeMaterial::AddTexture(unsigned int idx, 46 | unsigned int type, 47 | ComPtr tex, 48 | ComPtr textureResourceView, 49 | ComPtr texSampler) 50 | { 51 | _textures[type] = make_shared(TextureWrapper(idx, type, tex, textureResourceView, texSampler)); 52 | } 53 | -------------------------------------------------------------------------------- /ModelViewer/NodeMaterial.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | using namespace Microsoft::WRL; 6 | using namespace std; 7 | using namespace WinRTGLTFParser; 8 | 9 | class TextureWrapper 10 | { 11 | public: 12 | TextureWrapper(unsigned int idx, 13 | unsigned int type, 14 | ComPtr tex, 15 | ComPtr textureResourceView, 16 | ComPtr texSampler) : 17 | _idx(idx), 18 | _tex(tex), 19 | _textureResourceView(textureResourceView), 20 | _textureSampler(texSampler) 21 | { 22 | _type = type; 23 | } 24 | 25 | ComPtr GetSampler() { return _textureSampler; } 26 | ComPtr GetShaderResourceView() { return _textureResourceView; } 27 | ComPtr GetTexture() { return _tex; } 28 | unsigned int GetIndex() { return _idx; } 29 | unsigned int Type() { return _type; } 30 | 31 | private: 32 | ComPtr _textureSampler; 33 | ComPtr _textureResourceView; 34 | ComPtr _tex; 35 | unsigned int _idx; 36 | unsigned int _type; 37 | }; 38 | 39 | class NodeMaterial 40 | { 41 | public: 42 | NodeMaterial(); 43 | ~NodeMaterial(); 44 | 45 | void Initialise(GLTF_MaterialData^ data); 46 | void AddTexture(unsigned int idx, 47 | unsigned int type, 48 | ComPtr tex, 49 | ComPtr textureResourceView, 50 | ComPtr texSampler); 51 | void AddTexture(shared_ptr tex); 52 | 53 | shared_ptr GetTexture(unsigned int idx) { return _textures[idx]; } 54 | 55 | shared_ptr HasTextureId(unsigned int idx); 56 | bool HasTexture(unsigned int idx) { return _textures.find(idx) != _textures.end(); } 57 | size_t GetNumTextures() { return _textures.size(); } 58 | 59 | map>& Textures() { return _textures; } 60 | 61 | XMFLOAT4& BaseColourFactor() { return _baseColorFactor; } 62 | void SetBaseColourFactor(XMFLOAT4 bcf) { _baseColorFactor = bcf; } 63 | 64 | XMFLOAT3& EmissiveFactor() { return _emmissiveFactor; } 65 | 66 | float MetallicFactor() { return _metallicFactor; } 67 | float RoughnessFactor() { return _roughnessFactor; } 68 | 69 | private: 70 | map> _textures; 71 | wstring _name; 72 | 73 | XMFLOAT3 _emmissiveFactor = { 0.0f, 0.0f, 0.0f }; 74 | 75 | unsigned int _Pbrmetallicroughness_Basecolortexture = 0; 76 | unsigned int _Pbrmetallicroughness_Metallicroughnesstexture = 0; 77 | unsigned int _Normaltexture = 0; 78 | unsigned int _Occlusiontexture = 0; 79 | unsigned int _Emissivetexture = 0; 80 | 81 | XMFLOAT4 _baseColorFactor = { 1.0f, 1.0f, 1.0f, 1.0f }; 82 | float _metallicFactor = 1.0f; 83 | float _roughnessFactor = 1.0f; 84 | }; 85 | 86 | -------------------------------------------------------------------------------- /ModelViewer/Package.appxmanifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | ModelViewer 7 | Pete D 8 | Assets\StoreLogo.png 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | .gltf 28 | .glb 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /ModelViewer/RenderTexture.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "RenderTexture.h" 3 | #include "Common\DirectXHelper.h" 4 | 5 | using namespace ModelViewer; 6 | using namespace DX; 7 | 8 | RenderTexture::RenderTexture(const shared_ptr& deviceResources) : 9 | m_deviceResources(deviceResources) 10 | { 11 | } 12 | 13 | RenderTexture::~RenderTexture() 14 | { 15 | } 16 | 17 | void RenderTexture::Shutdown() 18 | { 19 | m_renderTargetTexture.Reset(); 20 | m_renderTargetView.Reset(); 21 | m_shaderResourceView.Reset(); 22 | } 23 | 24 | void RenderTexture::Initialize(int width, int height) 25 | { 26 | D3D11_TEXTURE2D_DESC textureDesc; 27 | 28 | // Initialize the render target texture description. 29 | ZeroMemory(&textureDesc, sizeof(textureDesc)); 30 | 31 | // Setup the render target texture description. 32 | textureDesc.Width = width; 33 | textureDesc.Height = height; 34 | textureDesc.MipLevels = 1; 35 | textureDesc.ArraySize = 1; 36 | textureDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; 37 | textureDesc.SampleDesc.Count = 1; 38 | textureDesc.Usage = D3D11_USAGE_DEFAULT; 39 | textureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE; 40 | textureDesc.CPUAccessFlags = 0; 41 | textureDesc.MiscFlags = 0; 42 | 43 | auto dev = m_deviceResources->GetD3DDevice(); 44 | 45 | // Create the render target texture. 46 | ThrowIfFailed(dev->CreateTexture2D(&textureDesc, NULL, m_renderTargetTexture.GetAddressOf())); 47 | 48 | // Setup the description of the render target view. 49 | D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc; 50 | renderTargetViewDesc.Format = textureDesc.Format; 51 | renderTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; 52 | renderTargetViewDesc.Texture2D.MipSlice = 0; 53 | 54 | // Create the render target view. 55 | ThrowIfFailed(dev->CreateRenderTargetView(m_renderTargetTexture.Get(), &renderTargetViewDesc, &m_renderTargetView)); 56 | 57 | // Setup the description of the shader resource view. 58 | D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc; 59 | shaderResourceViewDesc.Format = textureDesc.Format; 60 | shaderResourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; 61 | shaderResourceViewDesc.Texture2D.MostDetailedMip = 0; 62 | shaderResourceViewDesc.Texture2D.MipLevels = 1; 63 | 64 | // Create the shader resource view. 65 | ThrowIfFailed(dev->CreateShaderResourceView(m_renderTargetTexture.Get(), &shaderResourceViewDesc, &m_shaderResourceView)); 66 | } 67 | 68 | void RenderTexture::SetRenderTarget(ID3D11DepthStencilView *depthStencilView) 69 | { 70 | m_deviceResources->GetD3DDeviceContext()->OMSetRenderTargets(1, &m_renderTargetView, depthStencilView); 71 | } 72 | 73 | void RenderTexture::ClearRenderTarget(ID3D11DepthStencilView *depthStencilView, XMFLOAT4 colour) 74 | { 75 | auto dc = m_deviceResources->GetD3DDeviceContext(); 76 | float col[] = { colour.x, colour.y, colour.z, colour.w }; 77 | dc->ClearRenderTargetView(m_renderTargetView.Get(), &col[0]); 78 | 79 | // Clear the depth buffer. 80 | dc->ClearDepthStencilView(depthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0); 81 | } 82 | -------------------------------------------------------------------------------- /ModelViewer/RenderTexture.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | namespace ModelViewer 3 | { 4 | using namespace std; 5 | 6 | class RenderTexture 7 | { 8 | public: 9 | RenderTexture(const shared_ptr& deviceResources); 10 | ~RenderTexture(); 11 | 12 | void Initialize(int width, int height); 13 | void Shutdown(); 14 | 15 | void SetRenderTarget(ID3D11DepthStencilView *depthStencilView); 16 | void ClearRenderTarget(ID3D11DepthStencilView *depthStencilView, XMFLOAT4 colour); 17 | ID3D11ShaderResourceView *GetShaderResourceView() { return m_shaderResourceView.Get(); } 18 | ID3D11Texture2D *GetTexture() { return m_renderTargetTexture.Get(); } 19 | 20 | private: 21 | ComPtr m_renderTargetTexture; 22 | ComPtr m_renderTargetView; 23 | ComPtr m_shaderResourceView; 24 | shared_ptr m_deviceResources; 25 | }; 26 | } 27 | -------------------------------------------------------------------------------- /ModelViewer/RootPage.xaml: -------------------------------------------------------------------------------- 1 |  10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 50 | 51 | 53 | 54 | 55 | 56 | 57 | 62 | 68 | 69 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /ModelViewer/RootPage.xaml.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // RootPage.xaml.cpp 3 | // Implementation of the RootPage class 4 | // 5 | 6 | #include "pch.h" 7 | #include "RootPage.xaml.h" 8 | #include "DirectXPage.xaml.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "Scene\GraphNode.h" 16 | #include "ModelFactory.h" 17 | #include "SceneManager.h" 18 | #include "Utility.h" 19 | 20 | #include 21 | 22 | using namespace ModelViewer; 23 | 24 | using namespace Platform; 25 | using namespace Windows::Storage::Pickers; 26 | using namespace Windows::Storage; 27 | using namespace Windows::Foundation; 28 | using namespace Windows::Foundation::Collections; 29 | using namespace Windows::UI::Xaml; 30 | using namespace Windows::UI::Xaml::Controls; 31 | using namespace Windows::UI::Xaml::Controls::Primitives; 32 | using namespace Windows::UI::Xaml::Data; 33 | using namespace Windows::UI::Xaml::Input; 34 | using namespace Windows::UI::Xaml::Media; 35 | using namespace Windows::UI::Xaml::Navigation; 36 | using namespace concurrency; 37 | using namespace std; 38 | 39 | // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 40 | 41 | RootPage::RootPage() 42 | { 43 | ViewModel = ref new RootPageViewModel(); 44 | InitializeComponent(); 45 | } 46 | 47 | void RootPage::SaveInternalState(IPropertySet^ state) 48 | { 49 | //critical_section::scoped_lock lock(m_main->GetCriticalSection()); 50 | //m_deviceResources->Trim(); 51 | 52 | //// Stop rendering when the app is suspended. 53 | //m_main->StopRenderLoop(); 54 | 55 | //// Put code to save app state here. 56 | } 57 | 58 | // Loads the current state of the app for resume events. 59 | void RootPage::LoadInternalState(IPropertySet^ state) 60 | { 61 | // Put code to load app state here. 62 | 63 | // Start rendering when the app is resumed. 64 | //m_main->StartRenderLoop(); 65 | } 66 | 67 | void ModelViewer::RootPage::NavView_ItemInvoked(Windows::UI::Xaml::Controls::NavigationView^ sender, Windows::UI::Xaml::Controls::NavigationViewItemInvokedEventArgs^ args) 68 | { 69 | 70 | } 71 | 72 | void ModelViewer::RootPage::NavView_SelectionChanged(Windows::UI::Xaml::Controls::NavigationView^ sender, Windows::UI::Xaml::Controls::NavigationViewSelectionChangedEventArgs^ args) 73 | { 74 | 75 | } 76 | 77 | void ModelViewer::RootPage::MoreInfoBtn_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) 78 | { 79 | 80 | } 81 | 82 | void ModelViewer::RootPage::NavView_Loaded(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) 83 | { 84 | ContentFrame->Navigate(DirectXPage::typeid); 85 | NavView->IsPaneOpen = false; 86 | } 87 | 88 | -------------------------------------------------------------------------------- /ModelViewer/RootPage.xaml.h: -------------------------------------------------------------------------------- 1 | // 2 | // RootPage.xaml.h 3 | // Declaration of the RootPage class 4 | // 5 | 6 | #pragma once 7 | 8 | #include "RootPage.g.h" 9 | #include "ViewModels\RootPageViewModel.h" 10 | 11 | namespace ModelViewer 12 | { 13 | using namespace ViewModels; 14 | 15 | /// 16 | /// An empty page that can be used on its own or navigated to within a Frame. 17 | /// 18 | [Windows::Foundation::Metadata::WebHostHidden] 19 | public ref class RootPage sealed 20 | { 21 | public: 22 | RootPage(); 23 | 24 | void SaveInternalState(Windows::Foundation::Collections::IPropertySet^ state); 25 | void LoadInternalState(Windows::Foundation::Collections::IPropertySet^ state); 26 | 27 | Windows::UI::Xaml::Controls::Frame^ GetContentFrame() { return this->ContentFrame; } 28 | property RootPageViewModel ^ ViewModel; 29 | 30 | private: 31 | void NavView_ItemInvoked(Windows::UI::Xaml::Controls::NavigationView^ sender, Windows::UI::Xaml::Controls::NavigationViewItemInvokedEventArgs^ args); 32 | void NavView_SelectionChanged(Windows::UI::Xaml::Controls::NavigationView^ sender, Windows::UI::Xaml::Controls::NavigationViewSelectionChangedEventArgs^ args); 33 | void MoreInfoBtn_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); 34 | void NavView_Loaded(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); 35 | void ImportClick(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /ModelViewer/Scene/CameraNode.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "CameraNode.h" 3 | 4 | CameraNode::CameraNode(int index) : 5 | GraphContainerNode(index) 6 | { 7 | } 8 | 9 | CameraNode::~CameraNode() 10 | { 11 | } 12 | -------------------------------------------------------------------------------- /ModelViewer/Scene/CameraNode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GraphContainerNode.h" 3 | 4 | class CameraNode : 5 | public GraphContainerNode 6 | { 7 | public: 8 | CameraNode(int index); 9 | virtual ~CameraNode(); 10 | }; 11 | 12 | -------------------------------------------------------------------------------- /ModelViewer/Scene/GraphContainerNode.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "GraphContainerNode.h" 3 | #include "BufferManager.h" 4 | 5 | using namespace std; 6 | 7 | GraphContainerNode::GraphContainerNode(int index) : 8 | _index(index) 9 | { 10 | CoCreateGuid(&_guid); 11 | } 12 | 13 | GraphContainerNode::~GraphContainerNode() 14 | { 15 | } 16 | 17 | void GraphContainerNode::Update(StepTimer const& timer) 18 | { 19 | for (auto child : _children) 20 | { 21 | child->Update(timer); 22 | } 23 | } 24 | 25 | XMMATRIX GraphContainerNode::PreDraw(SceneContext& context, XMMATRIX model) 26 | { 27 | // Don't execute this until loaded.. 28 | 29 | XMMATRIX mat; 30 | if (_hasMatrix) 31 | { 32 | mat = XMLoadFloat4x4(&_matrix); 33 | } 34 | else 35 | { 36 | mat = 37 | XMMatrixTranspose( 38 | XMMatrixAffineTransformation( 39 | XMLoadFloat3(&_scale), 40 | XMLoadFloat3(&emptyVector), 41 | XMLoadFloat4(&_rotation), 42 | XMLoadFloat3(&_translation))); 43 | } 44 | if (!XMMatrixIsIdentity(model)) 45 | { 46 | mat = XMMatrixMultiply(model, mat); 47 | } 48 | model = mat; 49 | 50 | // Prepare to pass the updated model matrix to the shader 51 | XMStoreFloat4x4(&BufferManager::Instance().MVPBuffer().BufferData().model, mat); 52 | BufferManager::Instance().MVPBuffer().Update(*(DevResources())); 53 | return mat; 54 | } 55 | 56 | void GraphContainerNode::Draw(SceneContext& context, XMMATRIX model) 57 | { 58 | for (auto child : _children) 59 | { 60 | auto modelMatrix = child->PreDraw(context, model); 61 | child->Draw(context, modelMatrix); 62 | } 63 | } 64 | 65 | GraphNode *GraphContainerNode::FindChildByIndex(int index) 66 | { 67 | if (Index() == index) 68 | return this; 69 | for (auto child : _children) 70 | { 71 | auto ret = child->FindChildByIndex(index); 72 | if (ret != nullptr) 73 | return ret; 74 | } 75 | return nullptr; 76 | } 77 | 78 | GraphNode *GraphContainerNode::FindChildById(GUID id) 79 | { 80 | if (_guid == id) 81 | return this; 82 | for (auto child : _children) 83 | { 84 | return child->FindChildById(id); 85 | } 86 | return nullptr; 87 | } 88 | 89 | void GraphContainerNode::ForAllChildrenRecursive(function func) 90 | { 91 | //func(*this); 92 | for (auto child : _children) 93 | { 94 | func(*child); 95 | child->ForAllChildrenRecursive(func); 96 | } 97 | } 98 | 99 | void GraphContainerNode::ForAllChildrenRecursiveUntil(function func) 100 | { 101 | auto ret = func(*this); 102 | if (!ret) 103 | return; 104 | 105 | for (auto child : _children) 106 | { 107 | ret = func(*child); 108 | if (!ret) 109 | return; 110 | child->ForAllChildrenRecursive(func); 111 | } 112 | } 113 | 114 | BoundingBox GraphContainerNode::GetBoundingBox() 115 | { 116 | BoundingBox ret; 117 | for (auto child : _children) 118 | { 119 | ret.Grow(child->GetBoundingBox()); 120 | } 121 | return ret; 122 | } 123 | 124 | void GraphContainerNode::CreateDeviceDependentResources() 125 | { 126 | for (auto child : _children) 127 | { 128 | child->CreateDeviceDependentResources(); 129 | } 130 | } 131 | 132 | void GraphContainerNode::Initialise(const std::shared_ptr& deviceResources) 133 | { 134 | _deviceResources = deviceResources; 135 | } 136 | 137 | void GraphContainerNode::AddChild(shared_ptr child) 138 | { 139 | _children.push_back(child); 140 | } 141 | 142 | size_t GraphContainerNode::NumChildren() 143 | { 144 | return _children.size(); 145 | } 146 | 147 | shared_ptr GraphContainerNode::GetChild(int i) 148 | { 149 | return _children[i]; 150 | } 151 | 152 | const wstring& GraphContainerNode::Name() const 153 | { 154 | return _name; 155 | } 156 | 157 | void GraphContainerNode::SetName(const wstring& name) 158 | { 159 | if (_name != name) 160 | _name = name; 161 | } 162 | 163 | bool GraphContainerNode::IsSelected() 164 | { 165 | return _selected; 166 | } 167 | 168 | void GraphContainerNode::SetSelected(bool sel) 169 | { 170 | if (sel == _selected) 171 | return; 172 | 173 | // Set all child nodes accordingly.. 174 | ForAllChildrenRecursive([sel](GraphNode& node) 175 | { 176 | node.SetSelected(sel); 177 | }); 178 | } 179 | 180 | void GraphContainerNode::CreateTransform(GLTF_TransformData^ data) 181 | { 182 | // If we are handed a matrix, just apply that, otherwise break down into scale, rotate, translate 183 | // and generate the matrix from those.. 184 | if (data->hasMatrix) 185 | { 186 | XMFLOAT4X4 mat = 187 | { 188 | data->matrix[0], 189 | data->matrix[1], 190 | data->matrix[2], 191 | data->matrix[3], 192 | data->matrix[4], 193 | data->matrix[5], 194 | data->matrix[6], 195 | data->matrix[7], 196 | data->matrix[8], 197 | data->matrix[9], 198 | data->matrix[10], 199 | data->matrix[11], 200 | data->matrix[12], 201 | data->matrix[13], 202 | data->matrix[14], 203 | data->matrix[15] 204 | }; 205 | 206 | XMStoreFloat4x4(&BufferManager::Instance().MVPBuffer().BufferData().model, XMLoadFloat4x4(&mat)); 207 | } 208 | else 209 | { 210 | _scale = { data->scale[0], data->scale[1], data->scale[2] }; 211 | _translation = { data->translation[0], data->translation[1], data->translation[2] }; 212 | 213 | // Using the conversion from right-handed coordinate system of OpenGL to left-handed coordinate 214 | // system of DirectX 215 | // q.x, q.y, -q.z, -q.w 216 | // 217 | _rotation = { data->rotation[0], data->rotation[1], -data->rotation[2], -data->rotation[3] }; 218 | 219 | //XMVECTOR scale = { 1.0, 1.0, 1.0 }; 220 | //XMVECTOR translation = { 0.0, 0.0, 0.0 }; 221 | 222 | XMVECTOR ypr = { 0.0, 180.0, 0.0 }; 223 | // generate a quaternion from angle for testing... 224 | XMVECTOR rotQuat = XMQuaternionRotationRollPitchYawFromVector(ypr); 225 | 226 | //auto matrix = XMMatrixRotationQuaternion(quat); 227 | 228 | // Create matrix from scale 229 | auto matrix = XMMatrixAffineTransformation(XMLoadFloat3(&_scale), XMLoadFloat3(&emptyVector), XMLoadFloat4(&_rotation), XMLoadFloat3(&_translation)); 230 | 231 | // Prepare to pass the updated model matrix to the shader 232 | XMStoreFloat4x4(&BufferManager::Instance().MVPBuffer().BufferData().model, matrix); 233 | } 234 | } 235 | -------------------------------------------------------------------------------- /ModelViewer/Scene/GraphNode.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "GraphNode.h" 3 | 4 | GraphNode::GraphNode() 5 | { 6 | } 7 | 8 | GraphNode::~GraphNode() 9 | { 10 | } 11 | -------------------------------------------------------------------------------- /ModelViewer/Scene/GraphNode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Common\DeviceResources.h" 4 | #include "Common\StepTimer.h" 5 | #include "BoundingBox.h" 6 | #include 7 | #include "SceneContext.h" 8 | #include 9 | 10 | using namespace DX; 11 | using namespace DirectX; 12 | 13 | class GraphNode 14 | { 15 | public: 16 | GraphNode(); 17 | virtual ~GraphNode(); 18 | 19 | virtual void Update(StepTimer const& timer) = 0; 20 | virtual XMMATRIX PreDraw(SceneContext& context, XMMATRIX model) = 0; 21 | virtual void Draw(SceneContext& context, XMMATRIX model) = 0; 22 | virtual void CreateDeviceDependentResources() = 0; 23 | virtual void Initialise(const std::shared_ptr& deviceResources) = 0; 24 | virtual void AddChild(std::shared_ptr child) = 0; 25 | virtual void AfterLoad() = 0; 26 | virtual BoundingBox GetBoundingBox() = 0; 27 | virtual void ForAllChildrenRecursive(std::function func) = 0; 28 | virtual void ForAllChildrenRecursiveUntil(std::function func) = 0; 29 | virtual GraphNode *FindChildByIndex(int index) = 0; 30 | virtual GraphNode *FindChildById(GUID id) = 0; 31 | virtual size_t NumChildren() = 0; 32 | virtual std::shared_ptr GetChild(int i) = 0; 33 | virtual const std::wstring& Name() const = 0; 34 | virtual void SetName(const std::wstring& name) = 0; 35 | virtual int Index() = 0; 36 | virtual GUID GetId() = 0; 37 | virtual bool IsSelected() = 0; 38 | virtual void SetSelected(bool sel) = 0; 39 | }; 40 | 41 | -------------------------------------------------------------------------------- /ModelViewer/Scene/LightNode.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "LightNode.h" 3 | 4 | LightNode::LightNode(int index) : 5 | GraphContainerNode(index) 6 | { 7 | } 8 | 9 | LightNode::~LightNode() 10 | { 11 | } 12 | -------------------------------------------------------------------------------- /ModelViewer/Scene/LightNode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GraphContainerNode.h" 3 | 4 | class LightNode : 5 | public GraphContainerNode 6 | { 7 | public: 8 | LightNode(int index); 9 | ~LightNode(); 10 | }; 11 | 12 | -------------------------------------------------------------------------------- /ModelViewer/Scene/MeshNode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "GraphContainerNode.h" 4 | #include "Common\DeviceResources.h" 5 | #include 6 | #include "NodeMaterial.h" 7 | #include 8 | #include 9 | #include 10 | 11 | #include "BoundingBox.h" 12 | #include "ShaderCache.h" 13 | 14 | using namespace WinRTGLTFParser; 15 | using namespace Microsoft::WRL; 16 | using namespace std; 17 | using namespace DX; 18 | using namespace DirectX; 19 | 20 | class MeshNode : public GraphContainerNode 21 | { 22 | public: 23 | MeshNode(int index); 24 | virtual ~MeshNode(); 25 | 26 | void CompileAndLoadVertexShader(); 27 | void CompileAndLoadPixelShader(); 28 | 29 | virtual void Draw(SceneContext& context, XMMATRIX model); 30 | virtual void CreateDeviceDependentResources(); 31 | virtual void Initialise(const shared_ptr& deviceResources); 32 | virtual void AfterLoad(); 33 | 34 | void CreateBuffer(GLTF_BufferData^ data); 35 | void CreateTexture(GLTF_TextureData^ data); 36 | void CreateMaterial(GLTF_MaterialData^ data); 37 | void CreateTransform(GLTF_TransformData^ data); 38 | 39 | private: 40 | class BufferWrapper 41 | { 42 | public: 43 | BufferWrapper(GLTF_BufferData^ data, ComPtr buffer) : 44 | _data(data), 45 | _buffer(buffer) 46 | { 47 | } 48 | BufferWrapper() {} 49 | ComPtr& Buffer() { return _buffer; } 50 | 51 | GLTF_BufferData^ Data() { return _data; } 52 | 53 | private: 54 | GLTF_BufferData ^ _data; 55 | ComPtr _buffer; 56 | }; 57 | 58 | shared_ptr m_deviceResources; 59 | map _buffers; 60 | 61 | ComPtr _spSampler; 62 | shared_ptr _material; 63 | 64 | size_t m_indexCount; 65 | 66 | shared_ptr _currentMaterial; 67 | BoundingBox _bbox; 68 | 69 | bool m_hasUVs = false; 70 | 71 | shared_ptr m_vertexShaderWrapper; 72 | shared_ptr m_pixelShaderWrapper; 73 | }; 74 | 75 | -------------------------------------------------------------------------------- /ModelViewer/Scene/RootNode.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "RootNode.h" 3 | 4 | RootNode::RootNode(int index) : 5 | GraphContainerNode(index) 6 | { 7 | _name = wstring(L"Scene Root"); 8 | } 9 | 10 | RootNode::~RootNode() 11 | { 12 | } 13 | 14 | shared_ptr RootNode::SelectedNode() 15 | { 16 | // Do this for now until we need an insertion point 17 | return make_shared(*this); 18 | //return _selectedNode; 19 | } 20 | -------------------------------------------------------------------------------- /ModelViewer/Scene/RootNode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Scene\GraphContainerNode.h" 3 | 4 | class RootNode : 5 | public GraphContainerNode 6 | { 7 | public: 8 | RootNode(int index); 9 | ~RootNode(); 10 | 11 | shared_ptr SelectedNode(); 12 | 13 | private: 14 | shared_ptr _selectedNode; 15 | }; 16 | 17 | -------------------------------------------------------------------------------- /ModelViewer/Scene/SceneContext.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "SceneContext.h" 3 | #include 4 | 5 | SceneContext::SceneContext(ID3D11DeviceContext2 *context) : 6 | _context(context) 7 | { 8 | XMStoreFloat4x4(&_model, XMMatrixIdentity()); 9 | } 10 | 11 | SceneContext::~SceneContext() 12 | { 13 | } 14 | -------------------------------------------------------------------------------- /ModelViewer/Scene/SceneContext.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | struct ID3D11DeviceContext2; 4 | 5 | class SceneContext 6 | { 7 | public: 8 | SceneContext(ID3D11DeviceContext2 *context); 9 | ~SceneContext(); 10 | 11 | ID3D11DeviceContext2& context() { return *_context; } 12 | XMFLOAT4X4& model() { return _model; } 13 | void SetModel(XMFLOAT4X4& model) { _model = model; } 14 | 15 | private: 16 | ID3D11DeviceContext2 * _context; 17 | XMFLOAT4X4 _model; 18 | }; 19 | 20 | -------------------------------------------------------------------------------- /ModelViewer/SceneManager.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "SceneManager.h" 3 | 4 | using namespace std; 5 | 6 | SceneManager::SceneManager() 7 | { 8 | _sceneNode = make_shared(-1); 9 | } 10 | 11 | shared_ptr SceneManager::Current() 12 | { 13 | return _sceneNode; 14 | } 15 | 16 | const shared_ptr SceneManager::Current() const 17 | { 18 | return _sceneNode; 19 | } 20 | 21 | void SceneManager::AddNode(shared_ptr newNode) 22 | { 23 | Current()->AddChild(newNode); 24 | SceneChanged.notify(*this); 25 | } 26 | 27 | void SceneManager::SetDevResources(const shared_ptr& deviceResources) 28 | { 29 | _deviceResources = deviceResources; 30 | } 31 | 32 | void SceneManager::SetSelected(shared_ptr node) 33 | { 34 | // De-select all other nodes in the scene.. 35 | _sceneNode->ForAllChildrenRecursive([](GraphNode& nd) 36 | { 37 | nd.SetSelected(false); 38 | }); 39 | 40 | // Finally, set our node selected. 41 | node->SetSelected(true); 42 | SelectionChanged.notify(node); 43 | } 44 | 45 | shared_ptr SceneManager::GetSelected() 46 | { 47 | // Loop through the scene to find the one and only selected node (only supporting 48 | // single-selection for now) 49 | shared_ptr result; 50 | _sceneNode->ForAllChildrenRecursiveUntil([&result](GraphNode& nd) 51 | { 52 | if (nd.IsSelected()) 53 | { 54 | result.reset(&nd); 55 | } 56 | return true; 57 | }); 58 | 59 | return result; 60 | } 61 | -------------------------------------------------------------------------------- /ModelViewer/SceneManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Scene\RootNode.h" 4 | #include "Singleton.h" 5 | 6 | // Just using this singleton for the time-being until it becomes clearer on how 7 | // to best structure.. 8 | // 9 | using namespace DX; 10 | using namespace ModelViewer; 11 | 12 | class SceneManager : public Singleton 13 | { 14 | friend class Singleton; 15 | 16 | public: 17 | std::shared_ptr Current(); 18 | const std::shared_ptr Current() const; 19 | void AddNode(std::shared_ptr newNode); 20 | 21 | void SetDevResources(const std::shared_ptr& deviceResources); 22 | std::shared_ptr DevResources() { return _deviceResources; } 23 | 24 | sub_token RegisterForUpdates(std::function slot) 25 | { 26 | return SceneChanged.subscribe(slot); 27 | } 28 | 29 | void UnregisterForUpdates(sub_token conn) 30 | { 31 | conn.disconnect(); 32 | } 33 | 34 | sub_token RegisterForSelectionChanged(std::function)> slot) 35 | { 36 | return SelectionChanged.subscribe(slot); 37 | } 38 | 39 | void SetSelected(std::shared_ptr node); 40 | std::shared_ptr GetSelected(); 41 | 42 | protected: 43 | SceneManager(); 44 | 45 | private: 46 | 47 | // Just have once scene for now.. 48 | std::shared_ptr _sceneNode; 49 | std::shared_ptr _deviceResources; 50 | 51 | subject SceneChanged; 52 | subject> SelectionChanged; 53 | }; 54 | -------------------------------------------------------------------------------- /ModelViewer/ShaderCache.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "ShaderCache.h" 3 | 4 | size_t ShaderDescriptor::Hash() 5 | { 6 | if (!_hashCalculated) 7 | { 8 | hash shaderHash; 9 | _hash = shaderHash(*this); 10 | } 11 | return _hash; 12 | } -------------------------------------------------------------------------------- /ModelViewer/Singleton.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace ModelViewer 4 | { 5 | template 6 | class Singleton 7 | { 8 | public: 9 | static T& Instance() 10 | { 11 | static T instance; 12 | return instance; 13 | } 14 | Singleton(T const&) = delete; 15 | void operator=(T const&) = delete; 16 | 17 | protected: 18 | Singleton() {} 19 | ~Singleton() {} 20 | }; 21 | } -------------------------------------------------------------------------------- /ModelViewer/Subject.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "sub_token.h" 6 | 7 | using namespace std::placeholders; 8 | 9 | template 10 | class subject 11 | { 12 | public: 13 | void notify(Args... arg) 14 | { 15 | for (auto& kv : _map) 16 | { 17 | kv.second(arg...); 18 | } 19 | } 20 | 21 | sub_token subscribe(std::function fn) 22 | { 23 | sub_token tk; 24 | _map[tk] = fn; 25 | return tk; 26 | } 27 | 28 | //sub_token subscribe(const function fn) const 29 | //{ 30 | // sub_token tk; 31 | // _map[tk] = fn; 32 | // return tk; 33 | //} 34 | 35 | void unsubscribe(sub_token tk) 36 | { 37 | _map.erase(_map.find(tk)); 38 | } 39 | 40 | private: 41 | map> _map; 42 | }; 43 | -------------------------------------------------------------------------------- /ModelViewer/Utility.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "Utility.h" 3 | #include 4 | 5 | const wchar_t *newline = L"\n"; 6 | 7 | void Utility::Out(LPCTSTR sFormat, ...) 8 | { 9 | #ifndef NO_OUTPUT 10 | va_list argptr; 11 | va_start(argptr, sFormat); 12 | wchar_t buffer[2000]; 13 | HRESULT hr = StringCbVPrintf(buffer, sizeof(buffer), sFormat, argptr); 14 | if (STRSAFE_E_INSUFFICIENT_BUFFER == hr || S_OK == hr) 15 | { 16 | wcsncat_s(buffer, newline, (rsize_t)sizeof(buffer)); 17 | OutputDebugString(buffer); 18 | } 19 | else 20 | OutputDebugString(L"StringCbVPrintf error."); 21 | #endif 22 | } -------------------------------------------------------------------------------- /ModelViewer/Utility.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | class Utility 3 | { 4 | public: 5 | static void Out(LPCTSTR sFormat, ...); 6 | 7 | }; 8 | 9 | 10 | -------------------------------------------------------------------------------- /ModelViewer/ViewModels/DirectXPageViewModel.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "DirectXPageViewModel.h" 3 | 4 | using namespace ViewModels; 5 | 6 | DirectXPageViewModel::DirectXPageViewModel() : 7 | _proxy(this) 8 | { 9 | _data = Container::Instance().ResolveDirectXPageViewModelData(); 10 | } 11 | 12 | void DirectXPageViewModel::NotifySelectionChanged(shared_ptr node) 13 | { 14 | SelectedTransform = ref new TransformViewModel(node); 15 | } 16 | 17 | float DirectXPageViewModel::LightScale::get() 18 | { 19 | return _data->LightScale(); 20 | } 21 | 22 | void DirectXPageViewModel::LightScale::set(float val) 23 | { 24 | if (_data->LightScale() == val) 25 | return; 26 | OnPropertyChanged(getCallerName(__FUNCTION__)); 27 | _data->SetLightScale(val); 28 | } 29 | 30 | float DirectXPageViewModel::LightRotation::get() 31 | { 32 | return _data->LightRotation(); 33 | } 34 | 35 | void DirectXPageViewModel::LightRotation::set(float val) 36 | { 37 | if (_data->LightRotation() == val) 38 | return; 39 | _data->SetLightRotation(val); 40 | OnPropertyChanged(getCallerName(__FUNCTION__)); 41 | _data->SetLightDirection(ConvertDirection(LightRotation, LightPitch, 42 | const_cast(_data->LightDirection()))); 43 | } 44 | 45 | float DirectXPageViewModel::LightPitch::get() 46 | { 47 | return _data->LightPitch(); 48 | } 49 | 50 | void DirectXPageViewModel::LightPitch::set(float val) 51 | { 52 | if (_data->LightPitch() == val) 53 | return; 54 | _data->SetLightPitch(val); 55 | OnPropertyChanged(getCallerName(__FUNCTION__)); 56 | _data->SetLightDirection(ConvertDirection(LightRotation, LightPitch, 57 | const_cast(_data->LightDirection()))); 58 | } 59 | 60 | float DirectXPageViewModel::Ibl::get() 61 | { 62 | return _data->Ibl(); 63 | } 64 | 65 | void DirectXPageViewModel::Ibl::set(float val) 66 | { 67 | if (_data->Ibl() == val) 68 | return; 69 | _data->SetIbl(val); 70 | OnPropertyChanged(getCallerName(__FUNCTION__)); 71 | } 72 | 73 | Color DirectXPageViewModel::LightColour::get() 74 | { 75 | return ConvertColor(_data->LightColour()); 76 | } 77 | 78 | void DirectXPageViewModel::LightColour::set(Color val) 79 | { 80 | if (_data->LightColour()[0] == val.R && 81 | _data->LightColour()[1] == val.G && 82 | _data->LightColour()[2] == val.B) 83 | return; 84 | unsigned char col[3] = { val.R, val.G, val.B }; 85 | _data->SetLightColour(col); 86 | OnPropertyChanged(getCallerName(__FUNCTION__)); 87 | } 88 | 89 | bool DirectXPageViewModel::BaseColour::get() 90 | { 91 | return _data->BaseColour(); 92 | } 93 | 94 | void DirectXPageViewModel::BaseColour::set(bool val) 95 | { 96 | if (_data->BaseColour() == val) 97 | return; 98 | _data->SetBaseColour(val); 99 | OnPropertyChanged(getCallerName(__FUNCTION__)); 100 | } 101 | 102 | bool DirectXPageViewModel::Metallic::get() 103 | { 104 | return _data->Metallic(); 105 | } 106 | 107 | void DirectXPageViewModel::Metallic::set(bool val) 108 | { 109 | if (_data->Metallic() == val) 110 | return; 111 | _data->SetMetallic(val); 112 | OnPropertyChanged(getCallerName(__FUNCTION__)); 113 | } 114 | 115 | bool DirectXPageViewModel::Roughness::get() 116 | { 117 | return _data->Roughness(); 118 | } 119 | 120 | void DirectXPageViewModel::Roughness::set(bool val) 121 | { 122 | if (_data->Roughness() == val) 123 | return; 124 | _data->SetRoughness(val); 125 | OnPropertyChanged(getCallerName(__FUNCTION__)); 126 | } 127 | 128 | bool DirectXPageViewModel::Diffuse::get() 129 | { 130 | return _data->Diffuse(); 131 | } 132 | 133 | void DirectXPageViewModel::Diffuse::set(bool val) 134 | { 135 | if (_data->Diffuse() == val) 136 | return; 137 | _data->SetDiffuse(val); 138 | OnPropertyChanged(getCallerName(__FUNCTION__)); 139 | } 140 | 141 | bool DirectXPageViewModel::Specular::get() 142 | { 143 | return _data->Specular(); 144 | } 145 | 146 | void DirectXPageViewModel::Specular::set(bool val) 147 | { 148 | if (_data->Specular() == val) 149 | return; 150 | _data->SetSpecular(val); 151 | OnPropertyChanged(getCallerName(__FUNCTION__)); 152 | } 153 | 154 | bool DirectXPageViewModel::F::get() 155 | { 156 | return _data->F(); 157 | } 158 | 159 | void DirectXPageViewModel::F::set(bool val) 160 | { 161 | if (_data->F() == val) 162 | return; 163 | _data->SetF(val); 164 | OnPropertyChanged(getCallerName(__FUNCTION__)); 165 | } 166 | 167 | bool DirectXPageViewModel::G::get() 168 | { 169 | return _data->G(); 170 | } 171 | 172 | void DirectXPageViewModel::G::set(bool val) 173 | { 174 | if (_data->G() == val) 175 | return; 176 | _data->SetG(val); 177 | OnPropertyChanged(getCallerName(__FUNCTION__)); 178 | } 179 | 180 | bool DirectXPageViewModel::D::get() 181 | { 182 | return _data->D(); 183 | } 184 | 185 | void DirectXPageViewModel::D::set(bool val) 186 | { 187 | if (_data->D() == val) 188 | return; 189 | _data->SetD(val); 190 | OnPropertyChanged(getCallerName(__FUNCTION__)); 191 | } 192 | 193 | TransformViewModel^ DirectXPageViewModel::SelectedTransform::get() 194 | { 195 | return _selectedTransform; 196 | } 197 | 198 | void DirectXPageViewModel::SelectedTransform::set(TransformViewModel^ val) 199 | { 200 | if (_selectedTransform == val) 201 | return; 202 | _selectedTransform = val; 203 | OnPropertyChanged(getCallerName(__FUNCTION__)); 204 | } 205 | 206 | Color DirectXPageViewModel::ConvertColor(const unsigned char col[3]) 207 | { 208 | auto ret = new Color(); 209 | ret->R = col[0]; 210 | ret->G = col[1]; 211 | ret->B = col[2]; 212 | return *ret; 213 | } 214 | 215 | float *DirectXPageViewModel::ConvertDirection(float rotation, float pitch, float *data) 216 | { 217 | auto rot = rotation * M_PI / 180; 218 | auto ptch = pitch * M_PI / 180; 219 | data[0] = static_cast(sin(rot) * cos(ptch)); 220 | data[1] = static_cast(sin(ptch)); 221 | data[2] = static_cast(cos(rot) * cos(ptch)); 222 | return data; 223 | } 224 | -------------------------------------------------------------------------------- /ModelViewer/ViewModels/DirectXPageViewModel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Common/ViewModelBase.h" 4 | #include "DirectXPageViewModelData.h" 5 | #include "Content\Sample3DSceneRenderer.h" 6 | #include 7 | #include "Container.h" 8 | #include "TransformViewModel.h" 9 | #include "../SceneManager.h" 10 | 11 | #define _USE_MATH_DEFINES 12 | #include 13 | 14 | namespace ViewModels 15 | { 16 | using namespace Common; 17 | using namespace Windows::UI; 18 | using namespace Windows::UI::Xaml::Data; 19 | using namespace ModelViewer; 20 | 21 | [Bindable] 22 | public ref class DirectXPageViewModel sealed : public ViewModelBase 23 | { 24 | public: 25 | DirectXPageViewModel(); 26 | 27 | property float LightScale { float get(); void set(float val); } 28 | property float LightRotation { float get(); void set(float val); } 29 | property float LightPitch { float get(); void set(float val); } 30 | property float Ibl { float get(); void set(float val); } 31 | property Color LightColour { Color get(); void set(Color val); } 32 | property bool BaseColour { bool get(); void set(bool val); } 33 | property bool Metallic { bool get(); void set(bool val); } 34 | property bool Roughness { bool get(); void set(bool val); } 35 | property bool Diffuse { bool get(); void set(bool val); } 36 | property bool Specular { bool get(); void set(bool val); } 37 | property bool F { bool get(); void set(bool val); } 38 | property bool G { bool get(); void set(bool val); } 39 | property bool D { bool get(); void set(bool val); } 40 | property TransformViewModel^ SelectedTransform { TransformViewModel^ get(); void set(TransformViewModel^ val); } 41 | 42 | internal: 43 | void NotifySelectionChanged(shared_ptr node); 44 | 45 | class SelectionChangedProxy 46 | { 47 | public: 48 | SelectionChangedProxy(DirectXPageViewModel^ owner) : 49 | _owner(owner) 50 | { 51 | SceneManager::Instance().RegisterForSelectionChanged(bind(&SelectionChangedProxy::NotifySelectionChanged, this, _1)); 52 | } 53 | 54 | void NotifySelectionChanged(shared_ptr node) 55 | { 56 | _owner->NotifySelectionChanged(node); 57 | } 58 | 59 | private: 60 | DirectXPageViewModel ^ _owner; 61 | }; 62 | 63 | private: 64 | Color ConvertColor(const unsigned char col[3]); 65 | float *ConvertDirection(float rotation, float pitch, float *data); 66 | 67 | shared_ptr _data; 68 | TransformViewModel^ _selectedTransform; 69 | SelectionChangedProxy _proxy; 70 | }; 71 | 72 | } 73 | 74 | -------------------------------------------------------------------------------- /ModelViewer/ViewModels/RootPageViewModel.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "RootPageViewModel.h" 3 | #include "DelegateCommand.h" 4 | #include "SceneManager.h" 5 | #include "Utility.h" 6 | #include 7 | #include 8 | 9 | using namespace ViewModels; 10 | using namespace Windows::Storage::Pickers; 11 | 12 | RootPageViewModel::RootPageViewModel() 13 | { 14 | LoadFileCommand = ref new DelegateCommand(ref new ExecuteDelegate(this, &RootPageViewModel::ExecuteLoadCommand), nullptr); 15 | } 16 | 17 | class LoadingWrapper 18 | { 19 | public: 20 | LoadingWrapper(function ctor, function dtor) : 21 | _dtor(dtor) 22 | { 23 | Schedule(ctor); 24 | } 25 | 26 | future Schedule(function fn) 27 | { 28 | auto disp = Windows::ApplicationModel::Core::CoreApplication::MainView->CoreWindow->Dispatcher; 29 | co_await disp->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, 30 | ref new Windows::UI::Core::DispatchedHandler([fn]() { fn(); })); 31 | } 32 | 33 | ~LoadingWrapper() 34 | { 35 | Schedule(_dtor); 36 | } 37 | 38 | private: 39 | function _dtor; 40 | }; 41 | 42 | future> RootPageViewModel::LoadFileAsync() 43 | { 44 | auto fop = ref new FileOpenPicker(); 45 | fop->FileTypeFilter->Append(".glb"); 46 | fop->FileTypeFilter->Append(".gltf"); 47 | 48 | auto storageFile = co_await fop->PickSingleFileAsync(); 49 | if (storageFile == nullptr) 50 | co_return nullptr; 51 | 52 | // RAII-style for ensuring that the progress gets cleared robustly 53 | auto loader = make_unique([this]() { Loading = true; }, [this]() { Loading = false; }); 54 | 55 | Utility::Out(L"filename = %s", storageFile->Path->Data()); 56 | Filename = storageFile->Path; 57 | 58 | auto ret = co_await ModelFactory::Instance().CreateFromFileAsync(storageFile); 59 | co_return ret; 60 | } 61 | 62 | future RootPageViewModel::Load() 63 | { 64 | Utility::Out(L"At Start of Load"); 65 | auto node = co_await LoadFileAsync(); 66 | if (node == nullptr) 67 | co_return; 68 | 69 | Utility::Out(L"Loaded"); 70 | 71 | // Add the GraphNode to the scene 72 | auto current = SceneManager::Instance().Current(); 73 | SceneManager::Instance().AddNode(node); 74 | } 75 | 76 | void RootPageViewModel::ExecuteLoadCommand(Object^ param) 77 | { 78 | Load(); 79 | } 80 | 81 | bool RootPageViewModel::Loading::get() 82 | { 83 | return _loading; 84 | } 85 | 86 | void RootPageViewModel::Loading::set(bool val) 87 | { 88 | if (_loading == val) 89 | return; 90 | _loading = val; 91 | OnPropertyChanged(getCallerName(__FUNCTION__)); 92 | } 93 | 94 | String^ RootPageViewModel::Filename::get() 95 | { 96 | return _filename; 97 | } 98 | 99 | void RootPageViewModel::Filename::set(String^ val) 100 | { 101 | if (_filename == val) 102 | return; 103 | _filename = val; 104 | OnPropertyChanged(getCallerName(__FUNCTION__)); 105 | } 106 | -------------------------------------------------------------------------------- /ModelViewer/ViewModels/RootPageViewModel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Common/ViewModelBase.h" 4 | #include 5 | #include "ModelFactory.h" 6 | 7 | namespace ViewModels 8 | { 9 | using namespace Common; 10 | using namespace std; 11 | using namespace Windows::UI::Xaml::Input; 12 | using namespace Platform; 13 | 14 | [Windows::UI::Xaml::Data::Bindable] 15 | public ref class RootPageViewModel sealed : public ViewModelBase 16 | { 17 | public: 18 | RootPageViewModel(); 19 | 20 | property bool Loading { bool get(); void set(bool val); } 21 | property ICommand^ LoadFileCommand; 22 | property String^ Filename { String^ get(); void set(String^ val); } 23 | 24 | private: 25 | void ExecuteLoadCommand(Object^ param); 26 | future> RootPageViewModel::LoadFileAsync(); 27 | future RootPageViewModel::Load(); 28 | 29 | bool _loading = false; 30 | String^ _filename; 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /ModelViewer/ViewModels/TransformViewModel.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "TransformViewModel.h" 3 | 4 | using namespace ViewModels; 5 | 6 | float TransformViewModel::PositionX::get() 7 | { 8 | if (_selectedNode) 9 | { 10 | shared_ptr derived = 11 | dynamic_pointer_cast(_selectedNode); 12 | return derived->GetTranslation().x; 13 | } 14 | return 0.0f; 15 | } 16 | 17 | void TransformViewModel::PositionX::set(float val) 18 | { 19 | shared_ptr derived = 20 | dynamic_pointer_cast(_selectedNode); 21 | derived->SetTranslation(val, derived->GetTranslation().y, derived->GetTranslation().z); 22 | OnPropertyChanged(getCallerName(__FUNCTION__)); 23 | } 24 | 25 | float TransformViewModel::PositionY::get() 26 | { 27 | if (_selectedNode) 28 | { 29 | shared_ptr derived = 30 | dynamic_pointer_cast(_selectedNode); 31 | return derived->GetTranslation().y; 32 | } 33 | return 0.0f; 34 | } 35 | 36 | void TransformViewModel::PositionY::set(float val) 37 | { 38 | shared_ptr derived = 39 | dynamic_pointer_cast(_selectedNode); 40 | derived->SetTranslation(derived->GetTranslation().x, val, derived->GetTranslation().z); 41 | OnPropertyChanged(getCallerName(__FUNCTION__)); 42 | } 43 | 44 | float TransformViewModel::PositionZ::get() 45 | { 46 | if (_selectedNode) 47 | { 48 | shared_ptr derived = 49 | dynamic_pointer_cast(_selectedNode); 50 | return derived->GetTranslation().z; 51 | } 52 | return 0.0f; 53 | } 54 | 55 | void TransformViewModel::PositionZ::set(float val) 56 | { 57 | shared_ptr derived = 58 | dynamic_pointer_cast(_selectedNode); 59 | derived->SetTranslation(derived->GetTranslation().x, derived->GetTranslation().y, val); 60 | OnPropertyChanged(getCallerName(__FUNCTION__)); 61 | } 62 | 63 | float TransformViewModel::RotationX::get() 64 | { 65 | if (_selectedNode) 66 | { 67 | shared_ptr derived = 68 | dynamic_pointer_cast(_selectedNode); 69 | //return derived->GetRotationX(); 70 | return derived->GetRotation().x; 71 | } 72 | return 0.0f; 73 | } 74 | 75 | void TransformViewModel::RotationX::set(float val) 76 | { 77 | shared_ptr derived = 78 | dynamic_pointer_cast(_selectedNode); 79 | derived->SetRotationRoll(val); 80 | OnPropertyChanged(getCallerName(__FUNCTION__)); 81 | } 82 | 83 | float TransformViewModel::RotationY::get() 84 | { 85 | if (_selectedNode) 86 | { 87 | shared_ptr derived = 88 | dynamic_pointer_cast(_selectedNode); 89 | //return derived->GetRotationY(); 90 | return derived->GetRotation().y; 91 | } 92 | return 0.0f; 93 | } 94 | 95 | void TransformViewModel::RotationY::set(float val) 96 | { 97 | shared_ptr derived = 98 | dynamic_pointer_cast(_selectedNode); 99 | derived->SetRotationPitch(val); 100 | OnPropertyChanged(getCallerName(__FUNCTION__)); 101 | } 102 | 103 | float TransformViewModel::RotationZ::get() 104 | { 105 | if (_selectedNode) 106 | { 107 | shared_ptr derived = 108 | dynamic_pointer_cast(_selectedNode); 109 | //return derived->GetRotationZ(); 110 | return derived->GetRotation().z; 111 | } 112 | return 0.0f; 113 | } 114 | 115 | void TransformViewModel::RotationZ::set(float val) 116 | { 117 | shared_ptr derived = 118 | dynamic_pointer_cast(_selectedNode); 119 | derived->SetRotationYaw(val); 120 | OnPropertyChanged(getCallerName(__FUNCTION__)); 121 | } 122 | 123 | float TransformViewModel::ScaleX::get() 124 | { 125 | if (_selectedNode) 126 | { 127 | shared_ptr derived = 128 | dynamic_pointer_cast(_selectedNode); 129 | return derived->GetScale().x; 130 | } 131 | return 0.0f; 132 | } 133 | 134 | void TransformViewModel::ScaleX::set(float val) 135 | { 136 | shared_ptr derived = 137 | dynamic_pointer_cast(_selectedNode); 138 | derived->SetScale(val, derived->GetScale().y, derived->GetScale().z); 139 | OnPropertyChanged(getCallerName(__FUNCTION__)); 140 | } 141 | 142 | float TransformViewModel::ScaleY::get() 143 | { 144 | if (_selectedNode) 145 | { 146 | shared_ptr derived = 147 | dynamic_pointer_cast(_selectedNode); 148 | return derived->GetScale().y; 149 | } 150 | return 0.0f; 151 | } 152 | 153 | void TransformViewModel::ScaleY::set(float val) 154 | { 155 | shared_ptr derived = 156 | dynamic_pointer_cast(_selectedNode); 157 | derived->SetScale(derived->GetScale().x, val, derived->GetScale().z); 158 | OnPropertyChanged(getCallerName(__FUNCTION__)); 159 | } 160 | 161 | float TransformViewModel::ScaleZ::get() 162 | { 163 | if (_selectedNode) 164 | { 165 | shared_ptr derived = 166 | dynamic_pointer_cast(_selectedNode); 167 | return derived->GetScale().z; 168 | } 169 | return 0.0f; 170 | } 171 | 172 | void TransformViewModel::ScaleZ::set(float val) 173 | { 174 | shared_ptr derived = 175 | dynamic_pointer_cast(_selectedNode); 176 | derived->SetScale(derived->GetScale().x, derived->GetScale().y, val); 177 | OnPropertyChanged(getCallerName(__FUNCTION__)); 178 | } 179 | -------------------------------------------------------------------------------- /ModelViewer/ViewModels/TransformViewModel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Common/ViewModelBase.h" 4 | 5 | namespace ViewModels 6 | { 7 | using namespace Windows::UI::Xaml::Data; 8 | 9 | [Bindable] 10 | public ref class TransformViewModel sealed : public ViewModelBase 11 | { 12 | internal: 13 | TransformViewModel(shared_ptr node) : 14 | _selectedNode(node) 15 | { 16 | 17 | } 18 | 19 | public: 20 | property float PositionX { float get(); void set(float val); } 21 | property float PositionY { float get(); void set(float val); } 22 | property float PositionZ { float get(); void set(float val); } 23 | 24 | property float RotationX { float get(); void set(float val); } 25 | property float RotationY { float get(); void set(float val); } 26 | property float RotationZ { float get(); void set(float val); } 27 | 28 | property float ScaleX { float get(); void set(float val); } 29 | property float ScaleY { float get(); void set(float val); } 30 | property float ScaleZ { float get(); void set(float val); } 31 | 32 | private: 33 | shared_ptr _selectedNode; 34 | }; 35 | } -------------------------------------------------------------------------------- /ModelViewer/pch.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | -------------------------------------------------------------------------------- /ModelViewer/pch.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include "App.xaml.h" 19 | #include "Utility.h" 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "./Common/DirectXHelper.h" 28 | 29 | #include "ViewModels/RootPageViewModel.h" 30 | #include "ViewModels/DirectXPageViewModel.h" 31 | #include "GlyphConverter.h" 32 | #include "BooleanToVisibilityConverter.h" 33 | #include "FileSystemData.h" 34 | #include "DecimalPlacesConverter.h" -------------------------------------------------------------------------------- /ModelViewer/sub_token.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sub_token.h" 3 | 4 | int sub_token::count = 0; 5 | -------------------------------------------------------------------------------- /ModelViewer/sub_token.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class sub_token 4 | { 5 | public: 6 | sub_token() 7 | { 8 | _value = next(); 9 | } 10 | sub_token(const sub_token& other) 11 | { 12 | _value = other._value; 13 | } 14 | 15 | void operator=(const sub_token& other) 16 | { 17 | _value = other._value; 18 | } 19 | 20 | void disconnect() 21 | { 22 | //_subject->unsubscribe(*this); 23 | } 24 | 25 | bool operator==(const sub_token& other) const 26 | { 27 | if (other == *this) 28 | return false; 29 | return this->_value == other._value; 30 | } 31 | 32 | bool operator<(const sub_token& other) const 33 | { 34 | return this->_value < other._value; 35 | } 36 | 37 | int value() { return _value; } 38 | 39 | private: 40 | int next() { return ++count; } 41 | int _value; 42 | static int count; 43 | }; 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DirectX GLTF Viewer Sample 2 | This project was motivated by a lack of sample code demonstrating the graphics API agnostic nature of the [glTF specification](https://www.google.com). The sample code is written using modern C++, DirectX 11 and the Universal Windows Platform (UWP) for the client application. The client application could have been written using any application development platform that supports DirectX 11 rendering. This sample is a port of the [Khronos PBR WebGL Sample](https://github.com/KhronosGroup/glTF-WebGL-PBR) and supports the same feature set. 3 | 4 | ![Main Sample App Screenshot](https://github.com/Microsoft/glTF-DXViewer/blob/master/img/screenshot2.PNG) 5 | 6 | The screenshot is showing the DamagedHelmet sample file being rendered in the scene window, some controls to the right to adjust transforms and a Tree View control with the scene hierarchy. 7 | 8 | # Features 9 | 10 | * Physically Based Rendering (PBR) 11 | * Buffer Management 12 | * Specification Support 13 | * Loader 14 | * Environment Map 15 | * Selective PBR Rendering 16 | 17 | The selective PBR rendering allow you to turn on and off different parts of the PBR shader to provide a better understanding of the visual effect of each. 18 | 19 | ![Selective PBR Rendering](https://github.com/Microsoft/glTF-DXViewer/blob/master/img/selective-rendering.png) 20 | 21 | # Dependencies 22 | * [Microsoft.glTF.cpp](https://www.nuget.org/packages/Microsoft.glTF.CPP/) 23 | 24 | [Nuget](https://www.nuget.org/) was used for package management for installing the binary dependencies. 25 | 26 | # Building 27 | The original version of this project was built using Visual Studio 2017 Version 15.6.7 on Windows 10 Fall Creators Update (16299.0). However, the TreeView control was offered in the SDK from version 17134.0 so the project has been updated to require this removing the extra code dependency in the process. The project has also been testd with version 15.7.1 but there was a need to add the compiler flag '/d2CoroOptsWorkaround' as in coroutines some variables may get optimised away incorrectly causing an access violation under certain circumstances. The project has subsequently been tested in Visual Studio version 15.7.2. 28 | 29 | # Further Information 30 | Please see this [article series](http://peted.azurewebsites.net/gltf-directx/) for full details around features and coding for this sample. 31 | 32 | # Contributing 33 | 34 | This project welcomes contributions and suggestions. Most contributions require you to agree to a 35 | Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us 36 | the rights to use your contribution. For details, visit https://cla.microsoft.com. 37 | 38 | When you submit a pull request, a CLA-bot will automatically determine whether you need to provide 39 | a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions 40 | provided by the bot. You will only need to do this once across all repos using our CLA. 41 | 42 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 43 | For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or 44 | contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 45 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Security 4 | 5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/). 6 | 7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below. 8 | 9 | ## Reporting Security Issues 10 | 11 | **Please do not report security vulnerabilities through public GitHub issues.** 12 | 13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report). 14 | 15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey). 16 | 17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc). 18 | 19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: 20 | 21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) 22 | * Full paths of source file(s) related to the manifestation of the issue 23 | * The location of the affected source code (tag/branch/commit or direct URL) 24 | * Any special configuration required to reproduce the issue 25 | * Step-by-step instructions to reproduce the issue 26 | * Proof-of-concept or exploit code (if possible) 27 | * Impact of the issue, including how an attacker might exploit the issue 28 | 29 | This information will help us triage your report more quickly. 30 | 31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs. 32 | 33 | ## Preferred Languages 34 | 35 | We prefer all communications to be in English. 36 | 37 | ## Policy 38 | 39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd). 40 | 41 | 42 | -------------------------------------------------------------------------------- /SharedGLTFParser/GLBGLTFConverter.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/SharedGLTFParser/GLBGLTFConverter.cpp -------------------------------------------------------------------------------- /SharedGLTFParser/GLBGLTFConverter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "stdafx.h" 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace GLTFParser 14 | { 15 | using namespace Microsoft::glTF; 16 | using namespace std; 17 | 18 | enum class GLTFTextureType 19 | { 20 | BaseColour = 0, 21 | Normal = 1, 22 | Emission = 2, 23 | Occlusion = 3, 24 | MetallicRoughness = 4 25 | }; 26 | 27 | class GLTFFileData 28 | { 29 | public: 30 | 31 | class Callbacks 32 | { 33 | public: 34 | function Buffers; 35 | function Textures; 36 | function Materials; 37 | function Transform; 38 | function SceneNode; 39 | }; 40 | 41 | class ParserContext 42 | { 43 | public: 44 | ParserContext(const GLTFDocument& document, 45 | const Callbacks& callbacks, 46 | const GLTFResourceReader& resources) : 47 | _document(document), 48 | _callbacks(callbacks), 49 | _resources(resources) 50 | { 51 | } 52 | 53 | const GLTFDocument& document() const { return _document; } 54 | const Callbacks& callbacks() const { return _callbacks; } 55 | const GLTFResourceReader& resources() const { return _resources; } 56 | 57 | private: 58 | const GLTFDocument& _document; 59 | const Callbacks& _callbacks; 60 | const GLTFResourceReader& _resources; 61 | }; 62 | 63 | const Callbacks& EventHandlers() const { return _callbacks; } 64 | Callbacks& EventHandlers() { return _callbacks; } 65 | 66 | void Read(shared_ptr file, const string& baseUri, IStreamReader& gltfStreamReader); 67 | void CheckExtensions(const GLTFDocument& document); 68 | void ParseDocument(const ParserContext& parser); 69 | 70 | void LoadScene(const ParserContext& parser, const Scene& scene); 71 | void LoadMeshNode(const ParserContext& parser, const Node& mNode); 72 | void LoadTransform(const ParserContext& parser, const Node& mNode); 73 | void LoadSceneNode(const ParserContext& parser, const Node& sceneNode, int nodeIndex, int parentIndex); 74 | void LoadMaterialNode(const ParserContext& parser, const Material& mNode); 75 | void LoadMaterialTextures(const ParserContext& parser, const Material& mNode); 76 | void LoadTexture(const ParserContext& parser, const Texture& texture, GLTFTextureType type); 77 | void LoadBufferFromAccessorId(const ParserContext& parser, const string& accessorId, 78 | const string& bufferType); 79 | void LoadBuffer(const ParserContext& parser, const BufferView& bufferView, 80 | const string& bufferType, const Accessor& accessor) const; 81 | 82 | private: 83 | GLTFFileData::Callbacks _callbacks; 84 | 85 | enum ComponentType 86 | { 87 | BYTE = 5120, // 1 88 | UNSIGNED_BYTE = 5121, // 1 89 | SHORT = 5122, // 2 90 | UNSIGNED_SHORT = 5123, // 2 91 | UNSIGNED_INT = 5125, // 4 92 | FLOAT = 5126 // 4 93 | }; 94 | 95 | void PopulateDocument(); 96 | }; 97 | }; 98 | 99 | -------------------------------------------------------------------------------- /SharedGLTFParser/SharedGLTFParser.vcxitems: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 5 | true 6 | {80d8332c-b175-484b-ac43-86f494ec86b0} 7 | 8 | 9 | 10 | %(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory) 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | stdafx.h 19 | $(IntDir)$(TargetName).pch 20 | 21 | 22 | stdafx.h 23 | $(IntDir)$(TargetName).pch 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /SharedGLTFParser/SharedGLTFParser.vcxitems.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Source FIles 6 | 7 | 8 | Source FIles 9 | 10 | 11 | 12 | 13 | Header Files 14 | 15 | 16 | Header Files 17 | 18 | 19 | 20 | 21 | 22 | 23 | {caf0b4cb-f3cf-4ebc-9585-fa17068a8d55} 24 | 25 | 26 | {a4aba145-0f4e-4bba-b88a-93efa1476fed} 27 | 28 | 29 | -------------------------------------------------------------------------------- /SharedGLTFParser/gltfparser.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/SharedGLTFParser/gltfparser.cpp -------------------------------------------------------------------------------- /SharedGLTFParser/gltfparser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | // The following ifdef block is the standard way of creating macros which make exporting 9 | // from a DLL simpler. All files within this DLL are compiled with the GLTFPARSER_EXPORTS 10 | // symbol defined on the command line. This symbol should not be defined on any project 11 | // that uses this DLL. This way any other project whose source files include this file see 12 | // GLTFPARSER_API functions as being imported from a DLL, whereas this DLL sees symbols 13 | // defined with this macro as being exported. 14 | #ifdef GLTFPARSER_EXPORTS 15 | #define GLTFPARSER_API __declspec(dllexport) 16 | #else 17 | #define GLTFPARSER_API __declspec(dllimport) 18 | #endif 19 | 20 | typedef long HRESULT; 21 | 22 | class GLTFPARSER_API MaterialData 23 | { 24 | public: 25 | MaterialData() {} 26 | 27 | const char *MaterialName; 28 | float emmissiveFactor[3] = { 0.0f, 0.0f, 0.0f }; 29 | float baseColourFactor[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; 30 | float metallicFactor = 1.0f; 31 | float roughnessFactor = 1.0f; 32 | 33 | int Pbrmetallicroughness_Basecolortexture; 34 | int Pbrmetallicroughness_Metallicroughnesstexture; 35 | int Normaltexture; 36 | int Occlusiontexture; 37 | int Emissivetexture; 38 | }; 39 | 40 | class GLTFPARSER_API TextureData 41 | { 42 | public: 43 | TextureData() {} 44 | 45 | const void *pSysMem; 46 | size_t dataSize; 47 | unsigned int imgWidth; 48 | unsigned int imgHeight; 49 | unsigned int idx; 50 | unsigned int type; 51 | }; 52 | 53 | class GLTFPARSER_API TransformData 54 | { 55 | public: 56 | TransformData() 57 | { 58 | rotation[0] = rotation[1] = rotation[2] = rotation[3] = 0.0; 59 | translation[0] = translation[1] = translation[2] = 0.0; 60 | scale[0] = scale[1] = scale[2] = 1.0; 61 | } 62 | 63 | double rotation[4]; 64 | double translation[3]; 65 | double scale[3]; 66 | double matrix[16]; 67 | 68 | bool hasMatrix; 69 | }; 70 | 71 | class GLTFPARSER_API SceneNodeData 72 | { 73 | public: 74 | SceneNodeData(){} 75 | 76 | const char *Name; 77 | bool isMesh; 78 | int nodeIndex; 79 | int parentIndex; 80 | }; 81 | 82 | struct GLTFPARSER_API SubresourceData 83 | { 84 | const void *pSysMem; 85 | unsigned int SysMemPitch; 86 | unsigned int SysMemSlicePitch; 87 | unsigned int accessorIdx; 88 | }; 89 | 90 | struct GLTFPARSER_API BufferDesc 91 | { 92 | size_t ByteWidth; 93 | unsigned int BindFlags; 94 | unsigned int CPUAccessFlags; 95 | unsigned int MiscFlags; 96 | size_t StructureByteStride; 97 | const char *BufferContentType; 98 | size_t Count; 99 | }; 100 | 101 | class GLTFPARSER_API BufferData 102 | { 103 | public: 104 | BufferData(); 105 | SubresourceData subresource; 106 | BufferDesc desc; 107 | }; 108 | 109 | HRESULT GLTFPARSER_API ParseFile(std::shared_ptr inStr, 110 | const std::string& baseUri, 111 | Microsoft::glTF::IStreamReader& gltfStreamReader, 112 | std::function bufferCallback, 113 | std::function materialCallback, 114 | std::function textureCallback, 115 | std::function transformCallback, 116 | std::function sceneNodeCallback); 117 | -------------------------------------------------------------------------------- /SharedGLTFParser/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/SharedGLTFParser/stdafx.h -------------------------------------------------------------------------------- /SharedGLTFParser/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/SharedGLTFParser/targetver.h -------------------------------------------------------------------------------- /WinRTGLTFParser/WinRTGLTFParser.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6661f40e-9740-40d8-bdec-02b3fe9723e8 6 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tga;tiff;tif;png;wav;mfcribbon-ms 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /WinRTGLTFParser/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /WinRTGLTFParser/pch.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | -------------------------------------------------------------------------------- /WinRTGLTFParser/pch.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | -------------------------------------------------------------------------------- /glTF-DXViewer.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27130.2024 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GLBGLTFConverter", "GLBGLTFConverter\GLBGLTFConverter.vcxproj", "{F6FAFE3C-92C0-43E7-A64B-B38DFC793EB2}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gltfparser", "gltfparser\gltfparser.vcxproj", "{D3B2132D-132E-4B58-A828-B20EF9962A83}" 9 | EndProject 10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WinRTGLTFParser", "WinRTGLTFParser\WinRTGLTFParser.vcxproj", "{31117527-AF30-485C-A312-846BC6A25E0B}" 11 | EndProject 12 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SharedGLTFParser", "SharedGLTFParser\SharedGLTFParser.vcxitems", "{80D8332C-B175-484B-AC43-86F494EC86B0}" 13 | EndProject 14 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ModelViewer", "ModelViewer\ModelViewer.vcxproj", "{28B2A92C-D6ED-4A02-9448-B554BF5A95DC}" 15 | EndProject 16 | Global 17 | GlobalSection(SharedMSBuildProjectFiles) = preSolution 18 | SharedGLTFParser\SharedGLTFParser.vcxitems*{31117527-af30-485c-a312-846bc6a25e0b}*SharedItemsImports = 4 19 | SharedGLTFParser\SharedGLTFParser.vcxitems*{80d8332c-b175-484b-ac43-86f494ec86b0}*SharedItemsImports = 9 20 | SharedGLTFParser\SharedGLTFParser.vcxitems*{d3b2132d-132e-4b58-a828-b20ef9962a83}*SharedItemsImports = 4 21 | EndGlobalSection 22 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 23 | Debug|ARM = Debug|ARM 24 | Debug|x64 = Debug|x64 25 | Debug|x86 = Debug|x86 26 | Release|ARM = Release|ARM 27 | Release|x64 = Release|x64 28 | Release|x86 = Release|x86 29 | EndGlobalSection 30 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 31 | {F6FAFE3C-92C0-43E7-A64B-B38DFC793EB2}.Debug|ARM.ActiveCfg = Debug|Win32 32 | {F6FAFE3C-92C0-43E7-A64B-B38DFC793EB2}.Debug|x64.ActiveCfg = Debug|x64 33 | {F6FAFE3C-92C0-43E7-A64B-B38DFC793EB2}.Debug|x64.Build.0 = Debug|x64 34 | {F6FAFE3C-92C0-43E7-A64B-B38DFC793EB2}.Debug|x86.ActiveCfg = Debug|Win32 35 | {F6FAFE3C-92C0-43E7-A64B-B38DFC793EB2}.Debug|x86.Build.0 = Debug|Win32 36 | {F6FAFE3C-92C0-43E7-A64B-B38DFC793EB2}.Release|ARM.ActiveCfg = Release|Win32 37 | {F6FAFE3C-92C0-43E7-A64B-B38DFC793EB2}.Release|x64.ActiveCfg = Release|x64 38 | {F6FAFE3C-92C0-43E7-A64B-B38DFC793EB2}.Release|x64.Build.0 = Release|x64 39 | {F6FAFE3C-92C0-43E7-A64B-B38DFC793EB2}.Release|x86.ActiveCfg = Release|Win32 40 | {F6FAFE3C-92C0-43E7-A64B-B38DFC793EB2}.Release|x86.Build.0 = Release|Win32 41 | {D3B2132D-132E-4B58-A828-B20EF9962A83}.Debug|ARM.ActiveCfg = Debug|Win32 42 | {D3B2132D-132E-4B58-A828-B20EF9962A83}.Debug|x64.ActiveCfg = Debug|x64 43 | {D3B2132D-132E-4B58-A828-B20EF9962A83}.Debug|x64.Build.0 = Debug|x64 44 | {D3B2132D-132E-4B58-A828-B20EF9962A83}.Debug|x86.ActiveCfg = Debug|Win32 45 | {D3B2132D-132E-4B58-A828-B20EF9962A83}.Debug|x86.Build.0 = Debug|Win32 46 | {D3B2132D-132E-4B58-A828-B20EF9962A83}.Release|ARM.ActiveCfg = Release|Win32 47 | {D3B2132D-132E-4B58-A828-B20EF9962A83}.Release|x64.ActiveCfg = Release|x64 48 | {D3B2132D-132E-4B58-A828-B20EF9962A83}.Release|x64.Build.0 = Release|x64 49 | {D3B2132D-132E-4B58-A828-B20EF9962A83}.Release|x86.ActiveCfg = Release|Win32 50 | {D3B2132D-132E-4B58-A828-B20EF9962A83}.Release|x86.Build.0 = Release|Win32 51 | {31117527-AF30-485C-A312-846BC6A25E0B}.Debug|ARM.ActiveCfg = Debug|ARM 52 | {31117527-AF30-485C-A312-846BC6A25E0B}.Debug|ARM.Build.0 = Debug|ARM 53 | {31117527-AF30-485C-A312-846BC6A25E0B}.Debug|x64.ActiveCfg = Debug|x64 54 | {31117527-AF30-485C-A312-846BC6A25E0B}.Debug|x64.Build.0 = Debug|x64 55 | {31117527-AF30-485C-A312-846BC6A25E0B}.Debug|x86.ActiveCfg = Debug|Win32 56 | {31117527-AF30-485C-A312-846BC6A25E0B}.Debug|x86.Build.0 = Debug|Win32 57 | {31117527-AF30-485C-A312-846BC6A25E0B}.Release|ARM.ActiveCfg = Release|ARM 58 | {31117527-AF30-485C-A312-846BC6A25E0B}.Release|ARM.Build.0 = Release|ARM 59 | {31117527-AF30-485C-A312-846BC6A25E0B}.Release|x64.ActiveCfg = Release|x64 60 | {31117527-AF30-485C-A312-846BC6A25E0B}.Release|x64.Build.0 = Release|x64 61 | {31117527-AF30-485C-A312-846BC6A25E0B}.Release|x86.ActiveCfg = Release|Win32 62 | {31117527-AF30-485C-A312-846BC6A25E0B}.Release|x86.Build.0 = Release|Win32 63 | {28B2A92C-D6ED-4A02-9448-B554BF5A95DC}.Debug|ARM.ActiveCfg = Debug|ARM 64 | {28B2A92C-D6ED-4A02-9448-B554BF5A95DC}.Debug|ARM.Build.0 = Debug|ARM 65 | {28B2A92C-D6ED-4A02-9448-B554BF5A95DC}.Debug|ARM.Deploy.0 = Debug|ARM 66 | {28B2A92C-D6ED-4A02-9448-B554BF5A95DC}.Debug|x64.ActiveCfg = Debug|x64 67 | {28B2A92C-D6ED-4A02-9448-B554BF5A95DC}.Debug|x64.Build.0 = Debug|x64 68 | {28B2A92C-D6ED-4A02-9448-B554BF5A95DC}.Debug|x64.Deploy.0 = Debug|x64 69 | {28B2A92C-D6ED-4A02-9448-B554BF5A95DC}.Debug|x86.ActiveCfg = Debug|Win32 70 | {28B2A92C-D6ED-4A02-9448-B554BF5A95DC}.Debug|x86.Build.0 = Debug|Win32 71 | {28B2A92C-D6ED-4A02-9448-B554BF5A95DC}.Debug|x86.Deploy.0 = Debug|Win32 72 | {28B2A92C-D6ED-4A02-9448-B554BF5A95DC}.Release|ARM.ActiveCfg = Release|ARM 73 | {28B2A92C-D6ED-4A02-9448-B554BF5A95DC}.Release|ARM.Build.0 = Release|ARM 74 | {28B2A92C-D6ED-4A02-9448-B554BF5A95DC}.Release|ARM.Deploy.0 = Release|ARM 75 | {28B2A92C-D6ED-4A02-9448-B554BF5A95DC}.Release|x64.ActiveCfg = Release|x64 76 | {28B2A92C-D6ED-4A02-9448-B554BF5A95DC}.Release|x64.Build.0 = Release|x64 77 | {28B2A92C-D6ED-4A02-9448-B554BF5A95DC}.Release|x64.Deploy.0 = Release|x64 78 | {28B2A92C-D6ED-4A02-9448-B554BF5A95DC}.Release|x86.ActiveCfg = Release|Win32 79 | {28B2A92C-D6ED-4A02-9448-B554BF5A95DC}.Release|x86.Build.0 = Release|Win32 80 | {28B2A92C-D6ED-4A02-9448-B554BF5A95DC}.Release|x86.Deploy.0 = Release|Win32 81 | EndGlobalSection 82 | GlobalSection(SolutionProperties) = preSolution 83 | HideSolutionNode = FALSE 84 | EndGlobalSection 85 | GlobalSection(ExtensibilityGlobals) = postSolution 86 | SolutionGuid = {4CF78638-BA41-43CB-81CA-79986B55969F} 87 | EndGlobalSection 88 | EndGlobal 89 | -------------------------------------------------------------------------------- /gltfparser/dllmain.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/gltfparser/dllmain.cpp -------------------------------------------------------------------------------- /gltfparser/gltfparser.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /gltfparser/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /gltfparser/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/gltfparser/stdafx.cpp -------------------------------------------------------------------------------- /img/screenshot1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/img/screenshot1.PNG -------------------------------------------------------------------------------- /img/screenshot2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/img/screenshot2.PNG -------------------------------------------------------------------------------- /img/selective-rendering.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/glTF-DXViewer/06f22ffa48637c7eb2fa2f1f5eb1ec10c98a8a3a/img/selective-rendering.png --------------------------------------------------------------------------------