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.
9 // Developed by Minigraph
11 // Author(s): Alex Nankervis
17 #include "VectorMath.h"
18 #include "TextureManager.h"
19 #include "GpuBuffer.h"
32 format_h3d
, // native format
36 static const char *s_FormatString
[];
37 static int FormatFromFilename(const char *filename
);
43 bool Load(const char *filename
);
44 bool Save(const char *filename
) const;
51 const BoundingBox
& GetBoundingBox() const
53 return m_Header
.boundingBox
;
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
,
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
,
114 attrib_format_none
= 0,
117 attrib_format_ushort
,
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
135 uint32_t materialCount
;
136 uint32_t vertexDataByteSize
;
137 uint32_t indexDataByteSize
;
138 uint32_t vertexDataByteSizeDepth
;
140 BoundingBox boundingBox
;
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
;
173 Vector3 transparent
; // light passing through a transparent surface is multiplied by this filter color
175 float shininess
; // specular exponent
176 float specularStrength
; // multiplier on top of specular color
178 enum {maxTexPath
= 128};
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;
212 bool LoadH3D(const char *filename
);
213 #ifdef MODEL_ENABLE_ASSIMP
214 bool LoadAssimp(const char *filename
);
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
228 void OptimizeRemoveDuplicateVertices(bool depth
);
229 void OptimizePostTransform(bool depth
);
230 void OptimizePreTransform(bool depth
);
233 void ReleaseTextures();
235 D3D12_CPU_DESCRIPTOR_HANDLE
* m_SRVs
;