MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / TransformBuffer

Method TransformBuffer

Source/Engine/Graphics/Models/ModelData.cpp:228–283  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

226}
227
228void MeshData::TransformBuffer(const Matrix& matrix)
229{
230 // Compute matrix inverse transpose
231 Matrix inverseTransposeMatrix;
232 Matrix::Invert(matrix, inverseTransposeMatrix);
233 Matrix::Transpose(inverseTransposeMatrix, inverseTransposeMatrix);
234
235 // Transform blend shapes
236 for (auto& blendShape : BlendShapes)
237 {
238 const auto vv = blendShape.Vertices.Get();
239 for (int32 i = 0; i < blendShape.Vertices.Count(); i++)
240 {
241 auto& v = vv[i];
242
243 Float3 p = Positions[v.VertexIndex];
244 Float3 vp = p + v.PositionDelta;
245 Float3::Transform(vp, matrix, vp);
246 Float3::Transform(p, matrix, p);
247 v.PositionDelta = vp - p;
248
249 Float3 n = Normals[v.VertexIndex];
250 Float3 vn = n + v.NormalDelta;
251 vn.Normalize();
252 Float3::TransformNormal(vn, inverseTransposeMatrix, vn);
253 vn.Normalize();
254 Float3::TransformNormal(n, inverseTransposeMatrix, n);
255 n.Normalize();
256 v.NormalDelta = vn - n;
257 }
258 }
259
260 // Transform positions
261 const auto pp = Positions.Get();
262 for (int32 i = 0; i < Positions.Count(); i++)
263 {
264 auto& p = pp[i];
265 Float3::Transform(p, matrix, p);
266 }
267
268 // Transform normals and tangents
269 const auto nn = Normals.Get();
270 for (int32 i = 0; i < Normals.Count(); i++)
271 {
272 auto& n = nn[i];
273 Float3::TransformNormal(n, inverseTransposeMatrix, n);
274 n.Normalize();
275 }
276 const auto tt = Tangents.Get();
277 for (int32 i = 0; i < Tangents.Count(); i++)
278 {
279 auto& t = tt[i];
280 Float3::TransformNormal(t, inverseTransposeMatrix, t);
281 t.Normalize();
282 }
283}
284
285void MeshData::NormalizeBlendWeights()

Callers 2

buildInnerMethod · 0.80
ImportModelMethod · 0.80

Calls 6

InvertFunction · 0.50
TransposeFunction · 0.50
TransformClass · 0.50
GetMethod · 0.45
CountMethod · 0.45
NormalizeMethod · 0.45

Tested by

no test coverage detected