core: Fix wchar_t handling in TextRenderer.
[vkmodelviewer.git] / Model / Model.h
blobc5f3ec185bda3e3c58521832502ed8190f23e523
1 //
2 // Copyright (c) Microsoft. All rights reserved.
3 // This code is licensed under the MIT License (MIT).
4 // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
5 // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
6 // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
7 // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
8 //
9 // Developed by Minigraph
11 // Author(s): Alex Nankervis
12 // James Stanard
15 #pragma once
17 #include "VectorMath.h"
18 #include "TextureManager.h"
19 #include "GpuBuffer.h"
21 namespace Graphics
23 using namespace Math;
25 class Model
27 public:
29 enum
31 format_none = 0,
32 format_h3d, // native format
34 formats,
36 static const char *s_FormatString[];
37 static int FormatFromFilename(const char *filename);
39 Model();
40 ~Model();
42 void Clear();
43 bool Load(const char *filename);
44 bool Save(const char *filename) const;
46 struct BoundingBox
48 Vector3 min;
49 Vector3 max;
51 const BoundingBox& GetBoundingBox() const
53 return m_Header.boundingBox;
56 enum
58 attrib_mask_0 = (1 << 0),
59 attrib_mask_1 = (1 << 1),
60 attrib_mask_2 = (1 << 2),
61 attrib_mask_3 = (1 << 3),
62 attrib_mask_4 = (1 << 4),
63 attrib_mask_5 = (1 << 5),
64 attrib_mask_6 = (1 << 6),
65 attrib_mask_7 = (1 << 7),
66 attrib_mask_8 = (1 << 8),
67 attrib_mask_9 = (1 << 9),
68 attrib_mask_10 = (1 << 10),
69 attrib_mask_11 = (1 << 11),
70 attrib_mask_12 = (1 << 12),
71 attrib_mask_13 = (1 << 13),
72 attrib_mask_14 = (1 << 14),
73 attrib_mask_15 = (1 << 15),
75 // friendly name aliases
76 attrib_mask_position = attrib_mask_0,
77 attrib_mask_texcoord0 = attrib_mask_1,
78 attrib_mask_normal = attrib_mask_2,
79 attrib_mask_tangent = attrib_mask_3,
80 attrib_mask_bitangent = attrib_mask_4,
83 enum
85 attrib_0 = 0,
86 attrib_1 = 1,
87 attrib_2 = 2,
88 attrib_3 = 3,
89 attrib_4 = 4,
90 attrib_5 = 5,
91 attrib_6 = 6,
92 attrib_7 = 7,
93 attrib_8 = 8,
94 attrib_9 = 9,
95 attrib_10 = 10,
96 attrib_11 = 11,
97 attrib_12 = 12,
98 attrib_13 = 13,
99 attrib_14 = 14,
100 attrib_15 = 15,
102 // friendly name aliases
103 attrib_position = attrib_0,
104 attrib_texcoord0 = attrib_1,
105 attrib_normal = attrib_2,
106 attrib_tangent = attrib_3,
107 attrib_bitangent = attrib_4,
109 maxAttribs = 16
112 enum
114 attrib_format_none = 0,
115 attrib_format_ubyte,
116 attrib_format_byte,
117 attrib_format_ushort,
118 attrib_format_short,
119 attrib_format_float,
121 attrib_formats
124 struct Attrib
126 uint16_t offset; // byte offset from the start of the vertex
127 uint16_t normalized; // if true, integer formats are interpreted as [-1, 1] or [0, 1]
128 uint16_t components; // 1-4
129 uint16_t format;
132 struct Header
134 uint32_t meshCount;
135 uint32_t materialCount;
136 uint32_t vertexDataByteSize;
137 uint32_t indexDataByteSize;
138 uint32_t vertexDataByteSizeDepth;
140 BoundingBox boundingBox;
142 Header m_Header;
144 struct Mesh
146 BoundingBox boundingBox;
148 unsigned int materialIndex;
150 unsigned int attribsEnabled;
151 unsigned int attribsEnabledDepth;
152 unsigned int vertexStride;
153 unsigned int vertexStrideDepth;
154 Attrib attrib[maxAttribs];
155 Attrib attribDepth[maxAttribs];
157 unsigned int vertexDataByteOffset;
158 unsigned int vertexCount;
159 unsigned int indexDataByteOffset;
160 unsigned int indexCount;
162 unsigned int vertexDataByteOffsetDepth;
163 unsigned int vertexCountDepth;
165 Mesh *m_pMesh;
167 struct Material
169 Vector3 diffuse;
170 Vector3 specular;
171 Vector3 ambient;
172 Vector3 emissive;
173 Vector3 transparent; // light passing through a transparent surface is multiplied by this filter color
174 float opacity;
175 float shininess; // specular exponent
176 float specularStrength; // multiplier on top of specular color
178 enum {maxTexPath = 128};
179 enum {texCount = 6};
180 char texDiffusePath[maxTexPath];
181 char texSpecularPath[maxTexPath];
182 char texEmissivePath[maxTexPath];
183 char texNormalPath[maxTexPath];
184 char texLightmapPath[maxTexPath];
185 char texReflectionPath[maxTexPath];
187 enum {maxMaterialName = 128};
188 char name[maxMaterialName];
190 Material *m_pMaterial;
192 unsigned char *m_pVertexData;
193 unsigned char *m_pIndexData;
194 StructuredBuffer m_VertexBuffer;
195 ByteAddressBuffer m_IndexBuffer;
196 uint32_t m_VertexStride;
198 // optimized for depth-only rendering
199 unsigned char *m_pVertexDataDepth;
200 unsigned char *m_pIndexDataDepth;
201 StructuredBuffer m_VertexBufferDepth;
202 ByteAddressBuffer m_IndexBufferDepth;
203 uint32_t m_VertexStrideDepth;
205 D3D12_CPU_DESCRIPTOR_HANDLE* GetSRVs( uint32_t materialIdx ) const
207 return m_SRVs + materialIdx * 6;
210 private:
212 bool LoadH3D(const char *filename);
213 #ifdef MODEL_ENABLE_ASSIMP
214 bool LoadAssimp(const char *filename);
215 #endif
217 bool SaveH3D(const char *filename) const;
219 void LoadPostProcess(bool needToOptimize);
221 void ComputeMeshBoundingBox(unsigned int meshIndex, BoundingBox &bbox) const;
222 // requires all mesh bounding boxes to be computed
223 void ComputeGlobalBoundingBox(BoundingBox &bbox) const;
224 void ComputeAllBoundingBoxes();
226 #ifdef MODEL_ENABLE_OPTIMIZER
227 void Optimize();
228 void OptimizeRemoveDuplicateVertices(bool depth);
229 void OptimizePostTransform(bool depth);
230 void OptimizePreTransform(bool depth);
231 #endif
233 void ReleaseTextures();
234 void LoadTextures();
235 D3D12_CPU_DESCRIPTOR_HANDLE* m_SRVs;