MCPcopy Create free account
hub / github.com/TheRealMJP/DeferredTexturing / InitFromAssimpMesh

Method InitFromAssimpMesh

SampleFramework12/v1.00/Graphics/Model.cpp:128–201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

126}
127
128void Mesh::InitFromAssimpMesh(const aiMesh& assimpMesh, float sceneScale, MeshVertex* dstVertices, uint16* dstIndices)
129{
130 numVertices = assimpMesh.mNumVertices;
131 numIndices = assimpMesh.mNumFaces * 3;
132
133 indexType = IndexType::Index16Bit;
134 if(numVertices > 0xFFFF)
135 {
136 AssertMsg_(false, "32-bit indices not currently supported");
137 // indexSize = 4;
138 // indexType = IndexType::Index32Bit;
139 }
140
141
142 if(assimpMesh.HasPositions())
143 {
144 // Compute the AABB of the mesh, and copy the positions
145 aabbMin = FloatMax;
146 aabbMax = -FloatMax;
147
148 for(uint64 i = 0; i < numVertices; ++i)
149 {
150 Float3 position = ConvertVector(assimpMesh.mVertices[i]) * sceneScale;
151 aabbMin.x = Min(aabbMin.x, position.x);
152 aabbMin.y = Min(aabbMin.y, position.y);
153 aabbMin.z = Min(aabbMin.z, position.z);
154
155 aabbMax.x = Max(aabbMax.x, position.x);
156 aabbMax.y = Max(aabbMax.y, position.y);
157 aabbMax.z = Max(aabbMax.z, position.z);
158
159 dstVertices[i].Position = position;
160 }
161 }
162
163 if(assimpMesh.HasNormals())
164 {
165 for(uint64 i = 0; i < numVertices; ++i)
166 dstVertices[i].Normal = ConvertVector(assimpMesh.mNormals[i]);
167 }
168
169 if(assimpMesh.HasTextureCoords(0))
170 {
171 for(uint64 i = 0; i < numVertices; ++i)
172 dstVertices[i].UV = ConvertVector(assimpMesh.mTextureCoords[0][i]).To2D();
173 }
174
175 if(assimpMesh.HasTangentsAndBitangents())
176 {
177 for(uint64 i = 0; i < numVertices; ++i)
178 {
179 dstVertices[i].Tangent = ConvertVector(assimpMesh.mTangents[i]);
180 dstVertices[i].Bitangent = ConvertVector(assimpMesh.mBitangents[i]) * -1.0f;
181 }
182 }
183
184 // Copy the index data
185 const uint64 numTriangles = assimpMesh.mNumFaces;

Callers 1

CreateWithAssimpMethod · 0.80

Calls 9

ConvertVectorFunction · 0.85
MinFunction · 0.85
MaxFunction · 0.85
To2DMethod · 0.80
HasPositionsMethod · 0.45
HasNormalsMethod · 0.45
HasTextureCoordsMethod · 0.45
InitMethod · 0.45

Tested by

no test coverage detected