1 /*
2 ---------------------------------------------------------------------------
3 Open Asset Import Library (assimp)
4 ---------------------------------------------------------------------------
5
6 Copyright (c) 2006-2021, assimp team
7
8 All rights reserved.
9
10 Redistribution and use of this software in source and binary forms,
11 with or without modification, are permitted provided that the following
12 conditions are met:
13
14 * Redistributions of source code must retain the above
15 copyright notice, this list of conditions and the
16 following disclaimer.
17
18 * Redistributions in binary form must reproduce the above
19 copyright notice, this list of conditions and the
20 following disclaimer in the documentation and/or other
21 materials provided with the distribution.
22
23 * Neither the name of the assimp team, nor the names of its
24 contributors may be used to endorse or promote products
25 derived from this software without specific prior
26 written permission of the assimp team.
27
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 ---------------------------------------------------------------------------
40 */
41
42 #if (!defined AV_MAIN_H_INCLUDED)
43 #define AV_MAIN_H_INCLUDED
44
45 #define AI_SHADER_COMPILE_FLAGS D3DXSHADER_USE_LEGACY_D3DX9_31_DLL
46
47 // Because Dx headers include windef.h with min/max redefinition
48 #define NOMINMAX
49
50 // include resource definitions
51 #include "resource.h"
52
53 #include <assert.h>
54 #include <malloc.h>
55 #include <memory.h>
56 #include <stdio.h>
57 #include <stdlib.h>
58 #include <tchar.h>
59 #include <time.h>
60
61 // Include ASSIMP headers (XXX: do we really need all of them?)
62 #include <assimp/ai_assert.h>
63 #include <assimp/cfileio.h>
64 #include <assimp/cimport.h>
65 #include <assimp/postprocess.h>
66 #include <assimp/scene.h>
67 #include <assimp/DefaultLogger.hpp>
68 #include <assimp/IOStream.hpp>
69 #include <assimp/IOSystem.hpp>
70 #include <assimp/Importer.hpp>
71 #include <assimp/LogStream.hpp>
72
73 #include "Material/MaterialSystem.h" // aiMaterial class
74 #include <assimp/StringComparison.h> // ASSIMP_stricmp and ASSIMP_strincmp
75
76 #include <time.h>
77
78 // default movement speed
79 #define MOVE_SPEED 3.f
80
81 #include "AssetHelper.h"
82 #include "Background.h"
83 #include "Camera.h"
84 #include "Display.h"
85 #include "LogDisplay.h"
86 #include "LogWindow.h"
87 #include "MaterialManager.h"
88 #include "MeshRenderer.h"
89 #include "RenderOptions.h"
90 #include "Shaders.h"
91
92 // outside of namespace, to help Intellisense and solve boost::metatype_stuff_miracle
93 #include "AnimEvaluator.h"
94 #include "SceneAnimator.h"
95
96 namespace AssimpView {
97
98 //-------------------------------------------------------------------------------
99 // Function prototypes
100 //-------------------------------------------------------------------------------
101 int InitD3D(void);
102 int ShutdownD3D(void);
103 int CreateDevice(bool p_bMultiSample, bool p_bSuperSample, bool bHW = true);
104 int CreateDevice(void);
105 int ShutdownDevice(void);
106 int GetProjectionMatrix(aiMatrix4x4 &p_mOut);
107 int LoadAsset(void);
108 int CreateAssetData(void);
109 int DeleteAssetData(bool bNoMaterials = false);
110 int ScaleAsset(void);
111 int DeleteAsset(void);
112 int SetupFPSView();
113
114 aiVector3D GetCameraMatrix(aiMatrix4x4 &p_mOut);
115 int CreateMaterial(AssetHelper::MeshHelper *pcMesh, const aiMesh *pcSource);
116
117 void HandleMouseInputFPS(void);
118 void HandleMouseInputLightRotate(void);
119 void HandleMouseInputLocal(void);
120 void HandleKeyboardInputFPS(void);
121 void HandleMouseInputLightIntensityAndColor(void);
122 void HandleMouseInputSkyBox(void);
123 void HandleKeyboardInputTextureView(void);
124 void HandleMouseInputTextureView(void);
125
126 //-------------------------------------------------------------------------------
127 //
128 // Dialog procedure for the progress bar window
129 //
130 //-------------------------------------------------------------------------------
131 INT_PTR CALLBACK ProgressMessageProc(HWND hwndDlg, UINT uMsg,
132 WPARAM wParam, LPARAM lParam);
133
134 //-------------------------------------------------------------------------------
135 // Main message procedure of the application
136 //
137 // The function handles all incoming messages for the main window.
138 // However, if does not directly process input commands.
139 // NOTE: Due to the impossibility to process WM_CHAR messages in dialogs
140 // properly the code for all hotkeys has been moved to the WndMain
141 //-------------------------------------------------------------------------------
142 INT_PTR CALLBACK MessageProc(HWND hwndDlg, UINT uMsg,
143 WPARAM wParam, LPARAM lParam);
144
145 //-------------------------------------------------------------------------------
146 //
147 // Dialog procedure for the about dialog
148 //
149 //-------------------------------------------------------------------------------
150 INT_PTR CALLBACK AboutMessageProc(HWND hwndDlg, UINT uMsg,
151 WPARAM wParam, LPARAM lParam);
152
153 //-------------------------------------------------------------------------------
154 //
155 // Dialog procedure for the help dialog
156 //
157 //-------------------------------------------------------------------------------
158 INT_PTR CALLBACK HelpDialogProc(HWND hwndDlg, UINT uMsg,
159 WPARAM wParam, LPARAM lParam);
160
161 //-------------------------------------------------------------------------------
162 // Handle command line parameters
163 //
164 // The function loads an asset specified on the command line as first argument
165 // Other command line parameters are not handled
166 //-------------------------------------------------------------------------------
167 void HandleCommandLine(char *p_szCommand);
168
169 //-------------------------------------------------------------------------------
170 template <class type, class intype>
clamp(intype in)171 type clamp(intype in) {
172 // for unsigned types only ...
173 intype mask = (0x1u << (sizeof(type) * 8)) - 1;
174 return (type)std::max((intype)0, std::min(in, mask));
175 }
176
177 //-------------------------------------------------------------------------------
178 // Position of the cursor relative to the 3ds max' like control circle
179 //-------------------------------------------------------------------------------
180 enum EClickPos {
181 // The click was inside the inner circle (x,y axis)
182 EClickPos_Circle,
183 // The click was inside one of the vertical snap-ins
184 EClickPos_CircleVert,
185 // The click was inside onf of the horizontal snap-ins
186 EClickPos_CircleHor,
187 // the cklick was outside the circle (z-axis)
188 EClickPos_Outside
189 };
190
191 #if (!defined AI_VIEW_CAPTION_BASE)
192 #define AI_VIEW_CAPTION_BASE "Open Asset Import Library : Viewer "
193 #endif // !! AI_VIEW_CAPTION_BASE
194
195 //-------------------------------------------------------------------------------
196 // Evil globals
197 //-------------------------------------------------------------------------------
198 extern HINSTANCE g_hInstance /*= NULL*/;
199 extern HWND g_hDlg /*= NULL*/;
200 extern IDirect3D9 *g_piD3D /*= NULL*/;
201 extern IDirect3DDevice9 *g_piDevice /*= NULL*/;
202 extern IDirect3DVertexDeclaration9 *gDefaultVertexDecl /*= NULL*/;
203 extern double g_fFPS /*= 0.0f*/;
204 extern char g_szFileName[MAX_PATH];
205 extern ID3DXEffect *g_piDefaultEffect /*= NULL*/;
206 extern ID3DXEffect *g_piNormalsEffect /*= NULL*/;
207 extern ID3DXEffect *g_piPassThroughEffect /*= NULL*/;
208 extern ID3DXEffect *g_piPatternEffect /*= NULL*/;
209 extern bool g_bMousePressed /*= false*/;
210 extern bool g_bMousePressedR /*= false*/;
211 extern bool g_bMousePressedM /*= false*/;
212 extern bool g_bMousePressedBoth /*= false*/;
213 extern float g_fElpasedTime /*= 0.0f*/;
214 extern D3DCAPS9 g_sCaps;
215 extern bool g_bLoadingFinished /*= false*/;
216 extern HANDLE g_hThreadHandle /*= NULL*/;
217 extern float g_fWheelPos /*= -10.0f*/;
218 extern bool g_bLoadingCanceled /*= false*/;
219 extern IDirect3DTexture9 *g_pcTexture /*= NULL*/;
220
221 extern aiMatrix4x4 g_mWorld;
222 extern aiMatrix4x4 g_mWorldRotate;
223 extern aiVector3D g_vRotateSpeed /*= aiVector3D(0.5f,0.5f,0.5f)*/;
224
225 extern aiVector3D g_avLightDirs[1] /* =
226 { aiVector3D(-0.5f,0.6f,0.2f) ,
227 aiVector3D(-0.5f,0.5f,0.5f)} */
228 ;
229
230 extern POINT g_mousePos /*= {0,0};*/;
231 extern POINT g_LastmousePos /*= {0,0}*/;
232 extern bool g_bFPSView /*= false*/;
233 extern bool g_bInvert /*= false*/;
234 extern EClickPos g_eClick;
235 extern unsigned int g_iCurrentColor /*= 0*/;
236
237 // NOTE: The light intensity is separated from the color, it can
238 // directly be manipulated using the middle mouse button.
239 // When the user chooses a color from the palette the intensity
240 // is reset to 1.0
241 // index[2] is the ambient color
242 extern float g_fLightIntensity /*=0.0f*/;
243 extern D3DCOLOR g_avLightColors[3];
244
245 extern RenderOptions g_sOptions;
246 extern Camera g_sCamera;
247 extern AssetHelper *g_pcAsset /*= NULL*/;
248
249 //
250 // Contains the mask image for the HUD
251 // (used to determine the position of a click)
252 //
253 // The size of the image is identical to the size of the main
254 // HUD texture
255 //
256 extern unsigned char *g_szImageMask /*= NULL*/;
257
258 extern float g_fACMR /*= 3.0f*/;
259 extern IDirect3DQuery9 *g_piQuery;
260
261 extern bool g_bPlay /*= false*/;
262
263 extern double g_dCurrent;
264 extern float g_smoothAngle /*= 80.f*/;
265
266 extern unsigned int ppsteps, ppstepsdefault;
267 extern bool nopointslines;
268 } // namespace AssimpView
269
270 #endif // !! AV_MAIN_H_INCLUDED
271